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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 5 replies
  • 708 views
  • 2 likes
  • 5 in conversation