//http://api.worldbank.org/v2/country/chn;ago;br/indicator/EN.ATM.CO2E.PC?date=1970:2019&source=2&format=json&per_page=500 Names Default to Here(1); // API Calls url = "http://api.worldbank.org/v2/country/"; query = [=>]; query["date"] = "1970:2019"; // Adjust to desired time frame query["source"] = "2"; query["format"] = "json"; countryIDs = "all"; // Insert desired country IDs from world bank website (2 or 3 letter ID) or all for all countries, separate IDs with ';' indicatorIDs = "EN.ATM.CO2E.PC"; // Insert indicator ID from world bank website, separate IDs with ';', 60 indicators maximum // Initial Call to get total value request = New HTTP Request( URL( url || countryIDs || "/indicator/" || indicatorIDs), QueryString(query), Method( "GET" ) ); json = request << Send; aa = ParseJSON(json); query["per_page"] = aa[1]["total"]; // Fixes per_page to be equal to total so all values are included // Call to get all data request = New HTTP Request( URL( url || countryIDs || "/indicator/" || indicatorIDs), QueryString(query), Method( "GET" ) ); json = request << Send; aa = ParseJSON(json); data = aa[2]; // Years years = {}; for(i = 1, i <= N Items(data), i++, years[i] = data[i]["date"]; ); NumYears = Length(Associative Array(years) << Get Keys); // Get Indicators and Countries indicators = {}; countries = {}; j = 1; for(i = 1, i <= N Items(data), i+= NumYears, indicators[j] = data[i]["indicator"]["value"]; countries[j] = data[i]["country"]["value"]; j++; ); ind = Associative Array(indicators) << Get Keys; ctr = Associative Array(countries) << Get Keys; // Create Table Name tableName = ind[1]; for(i = 2, i <= N Items(ind), i++, // Add indicators tableName = tableName || "; " || ind[i]; ); // Add Country Names if(countryIDs == "all", tableName = tableName || " - All", tableName = tableName || " - " || ctr[1]; for(j = 2, j <= N Items(ctr), j++, tableName = tableName || ", " || ctr[j]; ); ); // Create Data Table dt = New Table(tableName); // Includes Indicators and Countries // Insert Columns for each Countries and Indicators dt << New Column("Country Name", "Character"); dt << New Column("Country Code", "Character"); dt << New Column("Indicator Name", "Character"); dt << New Column("Indicator Code", "Character"); // Input Year values for(i = NumYears, i >= 1, i--, dt << New Column(years[i]); ); // Insert Country and Indicator Info j = 1; for(i = 1, i <= N Items(data), i+=NumYears, dt << Add Rows(1); Column(1)[j] = data[i]["country"]["value"]; Column(2)[j] = data[i]["countryiso3code"]; Column(3)[j] = data[i]["indicator"]["value"]; Column(4)[j] = data[i]["indicator"]["id"]; j++; ); // Insert Data Values for(k = 1, k < j, k++, // Rows for(i = NumYears, i >= 1, i--, // Columns n = (k)*NumYears - (i-1); // Data Value Column(i+4)[k] = Num(data[n]["value"]); // Offset Column by 4 ); ); Graph Builder( Size( 1020, 639 ), Show Control Panel( 0 ), Variables( Color( :Name( "2000" ) ), Shape( :Country Name ) ), Elements( Map Shapes( Legend( 4 ) ) ), Column Switcher( :Name( "2000" ), {:Name( "1970" ), :Name( "1971" ), :Name( "1972" ), :Name( "1973" ), :Name( "1974" ), :Name( "1975" ), :Name( "1976" ), :Name( "1977" ), :Name( "1978" ), :Name( "1979" ), :Name( "1980" ), :Name( "1981" ), :Name( "1982" ), :Name( "1983" ), :Name( "1984" ), :Name( "1985" ), :Name( "1986" ), :Name( "1987" ), :Name( "1988" ), :Name( "1989" ), :Name( "1990" ), :Name( "1991" ), :Name( "1992" ), :Name( "1993" ), :Name( "1994" ), :Name( "1995" ), :Name( "1996" ), :Name( "1997" ), :Name( "1998" ), :Name( "1999" ), :Name( "2000" ), :Name( "2001" ), :Name( "2002" ), :Name( "2003" ), :Name( "2004" ), :Name( "2005" ), :Name( "2006" ), :Name( "2007" ), :Name( "2008" ), :Name( "2009" ), :Name( "2010" ), :Name( "2011" ), :Name( "2012" ), :Name( "2013" ), :Name( "2014" ), :Name( "2015" ), :Name( "2016" ), :Name( "2017" ), :Name( "2018" ), :Name( "2019" )} ) ); /* Disclaimer by SAS Institute Inc. License Agreement for Corrective Code or Additional Functionality SAS INSTITUTE INC. IS PROVIDING YOU WITH THE COMPUTER SOFTWARE CODE INCLUDED WITH THIS AGREEMENT ("CODE") ON AN "AS IS" BASIS, AND AUTHORIZES YOU TO USE THE CODE SUBJECT TO THE TERMS HEREOF. BY USING THE CODE, YOU AGREE TO THESE TERMS. YOUR USE OF THE CODE IS AT YOUR OWN RISK. SAS INSTITUTE INC. MAKES NO REPRESENTATION OR WARRANTY, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE, WITH RESPECT TO THE CODE. The Code is intended to be used solely as part of a product ("Software") you currently have licensed from SAS or one of its subsidiaries or authorized agents ("SAS"). The Code is designed to either correct an error in the Software or to add functionality to the Software, but has not necessarily been tested. Accordingly, SAS makes no representation or warranty that the Code will operate error-free. SAS is under no obligation to maintain or support the Code. Neither SAS nor its licensors shall be liable to you or any third party for any general, special, direct, indirect, consequential, incidental or other damages whatsoever arising out of or related to your use or inability to use the Code, even if SAS has been advised of the possibility of such damages. Except as otherwise provided above, the Code is governed by the same agreement that governs the Software. If you do not have an existing agreement with SAS governing the Software, you may not use the Code. (SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or trademarks of their respective companies.) */