BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PatrykSAS
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
PatrykSAS
Obsidian | Level 7
Still got errors
ERROR: Required operator not found in expression: date()
ERROR: Argument 2 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or %QSYSFUNC function reference is terminated.
Tom
Super User Tom
Super User

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;
PatrykSAS
Obsidian | Level 7
Thanks Tom, it works fine. I get it now

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 4 replies
  • 1693 views
  • 1 like
  • 3 in conversation