I want to import a table from a url that has dynamic characters, but the code I have below is not working. Is there a doable fix?
%let var1=2017;
%let var2='NC'; %let var9='Cary'; /
filename myfile url "http://aa.usno.navy.mil/cgi-bin/aa_rstablew.pl?ID=AA&year=&var1&task=0&state=&var2&place=&var9" lrecl=32767;
here is the original url::
filename myfile url "http://aa.usno.navy.mil/cgi-bin/aa_rstablew.pl?ID=AA&year=2017&task=0&state=NC&place=Cary" lrecl=32767;
There is no need to quote your macro variables NC and Cary.
%let var9= Cary;
There is no need to quote your macro variables NC and Cary.
%let var9= Cary;
@tobyfarms Please mark @collinelliot solution as correct.
Yep, now you can quote them with double quotes:
state = "&var2"; etc.
@tobyfarms Remember that macro variables work as find/replace text but that the code resulting MUST be valid SAS syntax. In your current questions once you replace the macro variables your code is not valid. You can see this by easily replacing the macro variable in place and you see the errors.
First one:
%let var1=2017;
%let var2='NC'; %let var9='Cary'; /
filename myfile url "http://aa.usno.navy.mil/cgi-bin/aa_rstablew.pl?ID=AA&year=&var1&task=0&state=&var2&place=&var9" lrecl=32767;
Replaced (you can see the extra quotations in comparison to your posted URL):
filename myfile url "http://aa.usno.navy.mil/cgi-bin/aa_rstablew.pl?ID=AA&year=2017&task=0&state='NC'&place='Cary'" lrecl=32767;
Second one:
state=&var2;
City=&var9;
Replaced:
state=NC; -> this expects NC to be a variable since no quotations now.
City=Cary;
Yes, that makes sense. However, when I do not use quotations or place VAR9, I reviece "." as the city & state columns of my results.
The reason I am trying to use the macro is because I have to do this for multiple locations (which can vary in the future).
THANKS!!!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.