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?
%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.;
%SYSFUNC executes a sas base function, but what does
today(), yymmddn8.
mean in sas base ?
You probably want:
%sysfunc(put(today(), yymmddn8.));
Try it.
The first 2 parts are working. the last part "var2" is where I'm getting the error.
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.
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.
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 ;
This also works!
thank you!
%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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.