BookmarkSubscribeRSS Feed
BenWW85
Fluorite | Level 6

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! 

 

 

1 REPLY 1
SASKiwi
PROC Star

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1072 views
  • 0 likes
  • 2 in conversation