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

Hi There, 

 

I am trying set up the following variable for a daily process

 

%let most_recent_file = data_201907;

 

such that "_201907" is based on the most recent data file available. The file is generated mid month every month, for the prior month's data. Example today is Aug 16 til Sep 15, I will use data_201907. From Sep 16 til Oct 15 I will use data_201908 etc. So I thought the logic should be something along the lines of: take today. Subtract 2 weeks. Then subtract 1 month. 

 

I tried the following:

 

%let today = %sysfunc(today(), yymmddn8.);
%put &today. ;

 

%let var1 = %sysfunc(intnx(week,%sysfunc(today()),-2,same),yymmddn8.);
%put &var1.;

 

%let var2 = %sysfunc(intnx(month,%sysfunc(&var1),-1,same),yymmn6.);
%put &var2.;

 

But I'm getting ERROR: Function name missing in %SYSFUNC or %QSYSFUNC macro function reference. 

 

Am I missing something really simple?

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

%let today = %sysfunc(today(), yymmddn8.);
%put &today. ;

 

%let var1 = %sysfunc(intnx(week,%sysfunc(today()),-2,same),yymmddn8.);
%put &var1.;

 

%let var2 = %sysfunc(intnx(month,%sysfunc(inputn(&var1,yymmdd8.)),-1,same),yymmn6.);
%put &var2.;

View solution in original post

8 REPLIES 8
Shmuel
Garnet | Level 18

%SYSFUNC executes a sas base function, but what does 

today(), yymmddn8.

mean in sas base ?

 

You probably want:

%sysfunc(put(today(), yymmddn8.));

Try it.

 

HYC876
Calcite | Level 5

The first 2 parts are working. the last part "var2" is where I'm getting the error.

HYC876
Calcite | Level 5

I've tried that too. 

got this: WARNING: An argument to the function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set
to a missing value.

Astounding
PROC Star

Here is the culprit:

 

%sysfunc(&var1)

 

There is no need to apply %SYSFUNC to &VAR1, since there is no function being used.  Just remove that particular %SYSFUNC.

Quentin
Super User

Hi,

 

In your second statement you successfully set &var=20190814.

 

The problem is that inside the third statement you have %sysfunc(&var1).  That doesn't work because %sysfunc() is used to call a function.  To do what you want, you could use %SYSFUNC to call the INPUTN function to convert 20190814 into a SAS date, e.g.:

 

%let var2 = %sysfunc(intnx(month,%sysfunc(inputn(&var1,yymmdd8.)),-1,same),yymmn6.);
%put &var2.;

That said, it looks like the formula could be today's date minus 15 days, then one month before that.  You can do that in one line, like:

%let mydate=%sysfunc(intnx(month
                          ,%sysfunc(today())-15
                          ,-1
                           )
                    ,yymmn6.
                    );
%put &=mydate ;

 

 

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
novinosrin
Tourmaline | Level 20

%let today = %sysfunc(today(), yymmddn8.);
%put &today. ;

 

%let var1 = %sysfunc(intnx(week,%sysfunc(today()),-2,same),yymmddn8.);
%put &var1.;

 

%let var2 = %sysfunc(intnx(month,%sysfunc(inputn(&var1,yymmdd8.)),-1,same),yymmn6.);
%put &var2.;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 4541 views
  • 1 like
  • 5 in conversation