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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
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: Call for Content

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!

Submit your idea!

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
  • 8 replies
  • 4424 views
  • 1 like
  • 5 in conversation