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
?
What should that $ do in front of macro variable names?
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
?
oh assuming all the macro variable are setup correctly etc
does infile statement allows macro variable being inside quotation mark?
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.
@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 ;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.