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.
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.
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.
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"
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: