BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
benjamin_2018
Fluorite | Level 6

I am using a program to download data from the Census API. I can successfully download the data, however, I am receiving a warning message: 

WARNING: Apparent symbolic reference FOR not resolved.

The reason is that the syntax required for the GET request requires a &for clause to define geographic parameters. In the example below, the request is for the total population of Alabama according to 5-year ACS estimates from the 2016-2020 survey. However, I do want to resolve a macro parameter ACS_YEAR in that same URL string. 

 

%let ACS_YEAR=2020;
filename hdrs TEMP;
filename out TEMP;

proc http
url="https://api.census.gov/data/&ACS_YEAR/acs/acs5?get=NAME,B01001_001E&for=state:01"
method="GET"
out=out
headerout=hdrs;
run;

DATA TEST;
INFILE OUT DLM = ',' FIRSTOBS = 2;
INPUT B01001_001E $ state $;
RUN;

I tried to add %LET FOR=&FOR thinking that FOR would resolve to &FOR but that resulted in an error. 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

 

Try

url="https://api.census.gov/data/&ACS_YEAR/acs/acs5?get=NAME,B01001_001E%nrstr(&for)=state:01"

The %nrstr macro function masks special characters  like the & from being processed by the macro processor. Likely could just use the %nrstr(&) but I think including the "for" as well may make it easier to follow later why the mask is needed.

View solution in original post

2 REPLIES 2
ballardw
Super User

 

Try

url="https://api.census.gov/data/&ACS_YEAR/acs/acs5?get=NAME,B01001_001E%nrstr(&for)=state:01"

The %nrstr macro function masks special characters  like the & from being processed by the macro processor. Likely could just use the %nrstr(&) but I think including the "for" as well may make it easier to follow later why the mask is needed.

Tom
Super User Tom
Super User

Add macro quoting.

58   %let ACS_YEAR=2020;
59   %put "https://api.census.gov/data/&ACS_YEAR/acs/acs5?get=NAME,B01001_001E%str(&)for=state:01" ;
"https://api.census.gov/data/2020/acs/acs5?get=NAME,B01001_001E&for=state:01"

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 343 views
  • 1 like
  • 3 in conversation