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,

I found the following two statements from a code written by someone else.

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

%let YYMM = %sysfunc(intnx(WEEKDAY,&Day_want,-1),yymmd.);

I can understand the use of %sysfunc in the first statement above only.

%sysfunc in the first  statement above returns the date of today as a SAS date which is then equated to a macro variable named Day_want.

Questions:

1. 1.  What is the role %sysfunc in the second statement? Is %sysfunc used for variety of things?

2. 2. In standard intnx function ‘interval’ term which is ‘WEEKDAY’ above has to be enclosed within single quotes but the second statement does not obey that rule but SAS generates the results.

Could someone help me.

Miris

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

RTM:

SAS(R) 9.2 Macro Language: Reference

Execute SAS functions or user-written functions.

...


Details

Because %SYSFUNC is a macro function, you do not need to enclose character values in quotation marks as you do in DATA step functions. For example, the arguments to the OPEN function are enclosed in quotation marks when the function is used alone, but do not require quotation marks when used within %SYSFUNC....

Your interpretation of the first step is also wrong. It is calling the function today in the first and the in the second it is calling a different function, intnx.

To use a sas function in open macro code, you need to to use SYSFUNC or QSYSFUNC to tell SAS that its not just text.

View solution in original post

2 REPLIES 2
Reeza
Super User

RTM:

SAS(R) 9.2 Macro Language: Reference

Execute SAS functions or user-written functions.

...


Details

Because %SYSFUNC is a macro function, you do not need to enclose character values in quotation marks as you do in DATA step functions. For example, the arguments to the OPEN function are enclosed in quotation marks when the function is used alone, but do not require quotation marks when used within %SYSFUNC....

Your interpretation of the first step is also wrong. It is calling the function today in the first and the in the second it is calling a different function, intnx.

To use a sas function in open macro code, you need to to use SYSFUNC or QSYSFUNC to tell SAS that its not just text.

Amir
PROC Star

Hi,

Both answers are taken from the documentation:

SAS(R) 9.2 Macro Language: Reference

1) "Execute SAS functions or user-written functions"

2) "Because %SYSFUNC is a macro function, you do not need to enclose character values in quotation marks as you do in DATA step functions."

Regards,

Amir.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1228 views
  • 3 likes
  • 3 in conversation