SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8

hi I have some macro variable 

e.g.

%let sampdate = $g_job_date;
data _null_;
yyyymmdd_L6=intnx('month',"$SAMPDATE."d,-6,'end');
call symput("YYYYMMDD_L6",PUT(YYMMDD_L6,YYMMDDN8.));
run;

 now my questions is does it get interpreted correctly inside infile statement like below:

data monthly.pd_pool;

infile "/boccc/miu/interface/monthly.pd_pool_id_&yyyymmdd_L6.";

 

let's say &yyyymmdd_L6. is 20231130

from infile statement 

infile "/boccc/miu/interface/monthly.pd_pool_id_&yyyymmdd_L6.";

 

does SAS know he has to retrieve the file 

monthly.pd_pool_id_20231130

?

5 REPLIES 5
andreas_lds
Jade | Level 19

What should that $ do in front of macro variable names?

ballardw
Super User

Did you try it and see?

Or even just try a %PUT statement to show the resolved value of the given statement.

If you have a question about a specific macro variable will resolve in a statement use %put and look in the log.

 

%let yyyymmdd_L6=20231130;

%put infile "/boccc/miu/interface/monthly.pd_pool_id_&yyyymmdd_L6.";

Since you do not show an example of how you may be combining elements in your infile statement hard to say anything else.

 

Do say that this raises all sorts of questions about what you are actually attempting:

%let sampdate = $g_job_date;

 $g_job_date is not a macro variable and your data step does not use the Sampdate macro variable created. That would be using a "&sampdate" not "$sampdate".

 


@HeatherNewton wrote:

hi I have some macro variable 

e.g.

%let sampdate = $g_job_date;
data _null_;
yyyymmdd_L6=intnx('month',"$SAMPDATE."d,-6,'end');
call symput("YYYYMMDD_L6",PUT(YYMMDD_L6,YYMMDDN8.));
run;

 now my questions is does it get interpreted correctly inside infile statement like below:

data monthly.pd_pool;

infile "/boccc/miu/interface/monthly.pd_pool_id_&yyyymmdd_L6.";

 

let's say &yyyymmdd_L6. is 20231130

from infile statement 

infile "/boccc/miu/interface/monthly.pd_pool_id_&yyyymmdd_L6.";

 

does SAS know he has to retrieve the file 

monthly.pd_pool_id_20231130

?


 

HeatherNewton
Quartz | Level 8

oh assuming all the macro variable are setup correctly etc

does infile statement allows macro variable being inside quotation mark? 

 

Kurt_Bremser
Super User

I am very sure we have covered this with you before.

Macro triggers (% and &) are resolved when enclosed in double quotes.

Macro triggers are NOT resolved when enclosed in single quotes.

 

Special case:

infile "some command '&complex_parameter.'" pipe;

Here the macro trigger will be resolved, as the outer double quotes also mask the single quotes.

Quentin
Super User

@HeatherNewton wrote:

oh assuming all the macro variable are setup correctly etc

does infile statement allows macro variable being inside quotation mark? 

 


The SAS language allows macro variables to be resolved inside double quotation marks.  To test it out, you can use the %PUT statement, e.g.:

 

%let yyyymmdd=20231130 ;
%put "/boccc/miu/interface/monthly.pd_pool_id_&yyyymmdd_L6.";

You will see that that code does not work you get:

1    %let yyyymmdd=20231130 ;
2    %put "/boccc/miu/interface/monthly.pd_pool_id_&yyyymmdd_L6.";
WARNING: Apparent symbolic reference YYYYMMDD_L6 not resolved.
"/boccc/miu/interface/monthly.pd_pool_id_&yyyymmdd_L6."

So SAS looked for a macro variable named YYYYMMDD_L6, which does not exist.  The answer here is to add a dot after the name of the macro variable, to tell the macro processor that the name of the macro variable has ended.

 

If you add a dot, the log will show that the code works:

5    %let yyyymmdd=20231130 ;
6    %put "/boccc/miu/interface/monthly.pd_pool_id_&yyyymmdd._L6.";
"/boccc/miu/interface/monthly.pd_pool_id_20231130_L6."

You don't have to worry about any special rules relating to the INPUT statement, or any other SAS statement when you want to use a macro variable.  SAS statements do not have any interaction with the macro language.   The macro language is generating SAS code.  So for examples like this, it's helpful to test your macro code with a simple %PUT statement, which will allow you to see the code generated by the macro language.  If that code looks good, then you can use it anywhere.  So you can be confident that you could do:

infile "/boccc/miu/interface/monthly.pd_pool_id_&yyyymmdd._L6.";

or

title "Data for monthly.pd_pool_id_&yyyymmdd._L6.";

or

data want ;
  date=input("&yyyymmdd",yymmdd8.) ;
  format date date9. ;
  put date= ;
run ;

 

The Boston Area SAS Users Group is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now at https://www.basug.org/events.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1153 views
  • 2 likes
  • 5 in conversation