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

Hi,

This is the first time I write a code with macro and I get stucked with seemingly very easy step.

%macro readdata(yrmo=);

data &yrmo;

          infile 'C:\Users\XXX\&yrmo';

          input cusip          $ 1-8 name $ 9-40 date          issue_date          maturity_date          trader_matrix $ flat_prc acc_int coupon          yield

duration amount_out          Moody_rat SP_rat callability $ call_prc putability $ put_prc ret ind_code

Fitch_rat index_flag convexity Duff_Phelps;

run;

%mend;

%readdata(yrmo = Y0173);

This code gives me an error message.

ERROR: Physical file does not exist, C:\XXX\&yrmo.

OK, the file actually exists and if I replace &yrmo with Y0173, the code works fine.

How should I get &yrmo automatically replaced by macro?

Any advice will be appreciated.  Thank you!

Yosh

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

The file name in your infile statement has to be surrounded by double not single quotes.  Otherwise, the macro variable won't resolve.

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

The file name in your infile statement has to be surrounded by double not single quotes.  Otherwise, the macro variable won't resolve.

tobyfarms
Fluorite | Level 6

@art297Does the same work accessing/importing a URL?  I want to import a table from a url that has dynamic characters.

 

The code I have below is not working.

 

 

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

 

nehalsanghvi
Pyrite | Level 9
Single quotes are not needed when assigning values to macro variables unless you want them as part of your string, which in your case I don't think you do. Try:
%let var2=NC; %let var9=Cary;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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