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

Hi SAS Forum,

A coder has written the following 3 sas statements with the purpose of  creating yester weekday (no just yesterday) in MMMDD format as a macro variable.

For example, when I ran below 3 statements just today (i.e. Jan 21), Jan20 should be auto typed into the log.

Yes it did the job.

/*statement 1*/ 

%let today = %sysfunc(date());

/*statement 2*/ 

%let yesterwkday= %sysfunc(intnx(WEEKDAY,&today,-1), monname3.)%qsubstr(%sysfunc(intnx(WEEKDAY,&today,-1),mmddyy4.),3,2) ;

/*statement 3*/ 

%PUT &yesterwkday;

To understand what “statement 2” does above, I dismantled it into 2 pieces and ran them separately (green and blue colors).

/*Green part*/

%let part1= %sysfunc(intnx(WEEKDAY,&today,-1), monname3.);

%put &part1;

Jan is typed in the log

Thanks to Reeza and Amir’s help, I think I understand green part (Interpretation: Macro function %sysfunc calls the embedded SAS function called intnx)

/*Blue part*/

%let part2= %qsubstr(%sysfunc(intnx(WEEKDAY,&today,-1),mmddyy4.),3,2) ;

%put &part2;

20 is typed in the log

I have googled and also understood the role of macro function %qsubstr (as opposed to just %substr), so can understand somewhat the part highlighted by blue color.

 

Question:

When I put green and blue color pieces together and try to understand how it finally generates Jan20, I get lost. In other words, there are two %sysfunc embedded. So, which %sysfunc works firsts and which %sysfunc works next and so on…

Could someone help me in understanding the long statement 2 as a whole.

Thanks

Miris

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You are over thinking the problem. Since in this problem they are independent the order of execution does not really matter.  Any more than asking do you add 3 and 4 first or add 5 and 6 in the following equation:   x = (3+4)*(5+6)

%SYSFUNC() is mainly just a way to call most SAS functions (there are a handful that do not work).

So think of nested call %sysfunc(X(...)) the same as if there was a macro function %x().

The main difference that %SYSFUNC() has over that is the optional second parameter that lets you specify a format to use to convert the results of the function being called to a character string (everything in macro is a character sting).  So your two examples you are using MONNAME3. and MMDDYY. as the formats.

Your BLUE section looks like it wants the two digit day of the month. That could more easily be coded this way. 

%sysfunc(intnx(weekday,&today,-1),ddmmyy2.)

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

You are over thinking the problem. Since in this problem they are independent the order of execution does not really matter.  Any more than asking do you add 3 and 4 first or add 5 and 6 in the following equation:   x = (3+4)*(5+6)

%SYSFUNC() is mainly just a way to call most SAS functions (there are a handful that do not work).

So think of nested call %sysfunc(X(...)) the same as if there was a macro function %x().

The main difference that %SYSFUNC() has over that is the optional second parameter that lets you specify a format to use to convert the results of the function being called to a character string (everything in macro is a character sting).  So your two examples you are using MONNAME3. and MMDDYY. as the formats.

Your BLUE section looks like it wants the two digit day of the month. That could more easily be coded this way. 

%sysfunc(intnx(weekday,&today,-1),ddmmyy2.)

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 1020 views
  • 0 likes
  • 2 in conversation