We’re smarter together. Learn from this collection of community knowledge and add your expertise.

University Edition sifts population data from 1980 to 2010

by SAS Employee cakramer on ‎11-06-2015 01:34 PM (435 Views)

 What’s this data?

 

Today, using data from the federal government, we’re going to examine world population by region between 1980 and 2010.

 

 

How to download

 

If you don’t already have University Edition, get it here and follow the instructions from the pdf carefully. If you need help with almost any aspect of using University Edition, check out these video tutorials. Additional resources are available in this article.

 

Download the csv file on this page. Save the file, and it's ready to bring into SAS University Edition.

 

 

How to get the data and prep it for analysis

 

There are several problems with these data. First, the data mixes countries and regions and there is no variable to make clear which row is which. You just have to know your geography. Second, the population data are read in as character strings, not numbers. "NA" is used for missing values and that causes it to be read in as character. So, we need to clean up the Earth.jpgcountries/regions and reformat those population fields.

 

The primary challenge with this data is removing the regions from the countries. The data comes in pre-sorted in alphabetical order by country and grouped by region. There will be a region total at the top and in alphabetical order the countries that make up the region are listed below. Then the next region total comes up and so on. The problem with this dataset is that the regions aren't marked any differently. This makes it pretty hard to isolate just the countries but, not impossible. Use the proc import to bring in your file. In your next datastep use the rename function on the variable "_" to make it country.

 

To convert the character data to numeric, we're going to use a MACRO. A MACRO executes the same code over and over, while replacing one key change to the code every time. To start a MACRO you always use the %MACRO command. Then you give your MACRO a name, in this case, "cleanup." In parentheses, you have one or more variables you are going to use when running this. These are variables that change every time. In the middle of the MACRO is everything you want to happen. You can have any code there: a data step, a model, or a graph. At the end of that code, close the macro with a %MEND.FreeDataFriday_graphic.jpg

 

For our MACRO, we have only one MACRO variable: the_var. We can replace this with a different value every time we run the MACRO. To run the MACRO, call the MACRO with the % sign in front. This should be written below your %MEND statement. In the parenthesis next to it, write the value of what should be replaced. You must do this for every value you want to be in the code. In this example, the first time we run the MACRO, we are replacing &the_var with _1980. It is really like an automatic copy-paste. You must run the code with a call after your %MEND statement or nothing will happen.

 

To remove the data that are not countries, we are going to use a "not in" statement. You specify your variable and then use the keywords not in and in parenthesis list every value you don't want, our region names. Since this is a character variable, don't forget to put quotes around each value, and commas in between. One thing to note, the log will report warnings, ignore them. The log is saying that there is non-numeric data in a variable formatted to be numeric. These are just the missing values in the dataset, and have automatically been converted to missing values. The log views it as an error, but SAS really just did some of our work for us.

 

 

Code

 

proc import datafile="/folders/myfolders/my_data/population by country.csv" 
out=pop_by_country dbms=csv;
run;

data population;
set pop_by_country;
rename _=Country;
run;

%MACRO cleanup(the_var);
data population;
set population;
Year&the_var=input(&the_var, 10.5);
drop &the_var;
run;

%MEND;

%cleanup(_1980);
%cleanup(_1981);
%cleanup(_1982);
%cleanup(_1983);
%cleanup(_1984);
%cleanup(_1985);
%cleanup(_1986);
%cleanup(_1987);
%cleanup(_1988);
%cleanup(_1989);
%cleanup(_1990);
%cleanup(_1991);
%cleanup(_1992);
%cleanup(_1993);
%cleanup(_1994);
%cleanup(_1995);
%cleanup(_1996);
%cleanup(_1997);
%cleanup(_1998);
%cleanup(_1999);
%cleanup(_2000);
%cleanup(_2001);
%cleanup(_2002);
%cleanup(_2003);
%cleanup(_2004);
%cleanup(_2005);
%cleanup(_2006);
%cleanup(_2007);
%cleanup(_2008);
%cleanup(_2009);
%cleanup(_2010);

data Countries_Only;
set population;
where country not in ("North America", "Central & South America",
"Antarctica", "Europe", "Eurasia", "Middle East", "Africa", "Asia & Oceania",
"World");
run;

proc univariate data=Countries_Only all;
var year_1980;
run;

proc univariate data=Countries_Only all;
var year_2010;
run;

 

 

 

 

post 8 1980 graph.JPGpost 8 2010 graph.JPG

 

 

 

What does this output mean?

 

Using proc univariate we can see some of the modeling of the data. In 2010 we can see that there are two countries that are far and away the two largest countries. It isn't labeled in the graphs above, but you can go back to the original data and find which countries have those values. These are China and India, China being the larger of the two. They are about four times as big as the third largest country (United States).

 

However, when you go back to the first year recorded you can see that the second highest country (India) was not quite so close to the highest (China) then. This can perhaps be explained by China’s one-child-per-family policy, implemented in the 1970s. You would expect population to increase exponentially, but China's slowed significantly.

 

Compare China's slower growth rate to India, which jumped 171% (1173.108 / 684.8877). China's grew 135% (1330.1412 /984.73646). China recently repealed the one-child law and will allow couples to have two children. This article has more information about China's policy change.

 

 

Now it’s your turn!

 

Did you find something else interesting in this data? Share in the comments. I’m glad to answer any questions.

 

 

Need data for learning?

 

The SAS Communities Library has a growing supply of free data sources that you can use in your training to become a data scientist. The easiest way to find articles about data sources is to type "Data for learning" in the communities site search field like so:

  

DataforLearning.PNG

We publish all articles about free data sources under the Analytics U label in the SAS Communities Library. Want email notifications when we add new content? Subscribe to the Analytics U label by clicking "Find A Community" in the right nav and selecting SAS Communities Library at the bottom of the list. In the Labels box in the right nav, click Analytics U:

 

AnalyticsU.PNG

 

Click Analytics U, then select "Subscribe" from the Options menu.

 

Happy Learning!

Comments
by Regular Contributor
on ‎11-08-2015 08:44 PM

Once again, you've done an amazing job presenting the data, analysis, and interpretations.  Fascinating how fast these countries have grown; I have problems trying to imagine the sheer number of people this represents!!

 

Looking forward to next week's article!

Chris

Your turn
Sign In!

Want to write an article? Sign in with your profile.