Hello
I want to refer to a specific table from the previous month. The tables have the following name structure: MY_TABLE_&DATE (in yymmn6. format) like LIB.MY_TABLE_202102 or LIB.MY_TABLE_202103 etc
Below is code that I've already done but It doesn't work
%let period=intnx("month",date(),-1,"same");
data TEST;
set LIB.MY_TABLE_%sysfunc(&period.,yymmn6.);
run;
Everything is text to the macro processor. So if you add quotes around constant text strings they quotes are part of the string.
Each SAS function you want to use in macro code needs to be wrapped in its own %SYSFUNC() macro function call.
%let period=%sysfunc(intnx(month,%sysfunc(date()),-1),yymmn6.);
data TEST;
set LIB.MY_TABLE_&period ;
run;
No quotes or double-quotes inside of %SYSFUNC, these are not needed and wrong.
%let period=%sysfunc(intnx(month,date(),-1,same));
%let period=%sysfunc(putn(&period,yymmn6.));
data TEST;
set LIB.MY_TABLE_.
run;
Everything is text to the macro processor. So if you add quotes around constant text strings they quotes are part of the string.
Each SAS function you want to use in macro code needs to be wrapped in its own %SYSFUNC() macro function call.
%let period=%sysfunc(intnx(month,%sysfunc(date()),-1),yymmn6.);
data TEST;
set LIB.MY_TABLE_&period ;
run;
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!
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.