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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.