Help using Base SAS procedures

What is the role of macro function %sysfunc in this code?

Accepted Solution Solved
Reply
Super Contributor
Posts: 338
Accepted Solution

What is the role of macro function %sysfunc in this code?

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


Accepted Solutions
Solution
‎01-20-2014 01:31 PM
Super User
Posts: 17,829

Re: What is the role of macro function %sysfunc in this code?

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


All Replies
Solution
‎01-20-2014 01:31 PM
Super User
Posts: 17,829

Re: What is the role of macro function %sysfunc in this code?

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.

Super Contributor
Posts: 282

Re: What is the role of macro function %sysfunc in this code?

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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