Getting API data into a SAS dataset format

Reply
Occasional Contributor
Posts: 5

Getting API data into a SAS dataset format

Looking for some help. This is my first attempt to pull data using an API. In the past I go out and download the U.S. Census American Community Survey files I need as CSV's and do a PROC IMPORT. I'd like to try and get only the few variables I need via their API. 

 

This is my code to get totals for all census tracts (1249) in my state:

 

 

filename test "C:\Users\n00b\Desktop\API_Test\test.txt";
PROC HTTP
URL= "http://api.census.gov/data/2015/acs5?get=NAME,B01001_001E&for=tract:*&in=state:08&in=county:*"
method = 'GET'
out=test;
run;

 

 

I pull it into a text file but it generates the following green text

 

 

WARNING: Apparent symbolic reference FOR not resolved.
WARNING: Apparent symbolic reference IN not resolved.
WARNING: Apparent symbolic reference IN not resolved.

I'm assuming because I have wildcards to get all the different tracts?

Also now that I have the API data, how do I get it into a SAS dataset format? Is there a way besides PROC IMPORT?

Can I ask for multiple variables from different tables on the same call or is it one request per line (e.g. Var 1 on Table A and Var 1 on Table B in the same line of code)?

 

Sorry this is probably basic stuff but I'm getting stuck. Any help appreciated! 

 

 

Super User
Posts: 4,026

Re: Getting API data into a SAS dataset format

The warning messages happen because SAS is interpreting the URL text &XXX as a reference to a macro variable you have not previously defined. Enclosing your URL string in single quotes rather that double quotes should remove the warnings.

 

As for reading in the text file, you could do that in a DATA step using an INFILE and an INPUT statement similar to:

 

data test;
  infile test;
  input column1 $ column2 $ column3 $;
run;

You can change the INPUT statement to match the layout of your text file. Please supply details of the layout if you need further help.

Ask a Question
Discussion stats
  • 1 reply
  • 176 views
  • 0 likes
  • 2 in conversation