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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
collinelliot
Barite | Level 11

There is no need to quote your macro variables NC and Cary.

 

%let var9= Cary;

 

 

View solution in original post

8 REPLIES 8
collinelliot
Barite | Level 11

There is no need to quote your macro variables NC and Cary.

 

%let var9= Cary;

 

 

tobyfarms
Fluorite | Level 6
Awesome - I believe that resolved my issue (and error). Many Thanks!
Reeza
Super User

@tobyfarms Please mark @collinelliot solution as correct.

tobyfarms
Fluorite | Level 6
Thanks for letting me know. New to the process!
tobyfarms
Fluorite | Level 6
@collinelliot in my next data step, my place holders for city and step are not populating. where I would list:
state=&var2;
City=&var9;

Is there a fix for this also?
collinelliot
Barite | Level 11

Yep, now you can quote them with double quotes:

 

state = "&var2"; etc.

Reeza
Super User

@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;

 

tobyfarms
Fluorite | Level 6

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!!!

Spoiler
 

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
  • 8 replies
  • 1803 views
  • 4 likes
  • 3 in conversation