Learning SAS? Welcome to the exclusive online community for all SAS learners.

Explanation of %sysfunc in macro

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Explanation of %sysfunc in macro

Hello all,

 

So I am trying to write a code in university edition to understand the utilization of %sysfunc for using datastep functions in macros. Now there is this line

%let dsid=%sysfunc(open(&mydata,i)); what it is doing is openning a dataset in a macro. But can anyone explain how exactly sysfunc is working here.? Code is attached below.


Accepted Solutions
Solution
4 weeks ago
SAS Super FREQ
Posts: 375

Re: Explanation of %sysfunc in macro

Posted in reply to Suvrojoti

http://go.documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n0q72zlfmfjplon1p3nprf85sdin.h...

 

It is an argument to the OPEN function.

 

opens the data set in INPUT mode (default). Values can be read but not modified. 'I' uses the strongest access mode available in the engine. That is, if the engine supports random access, OPEN defaults to random access. Otherwise, the file is opened in 'IN' mode automatically. Files are opened with sequential access and a system-level warning is set.

View solution in original post


All Replies
SAS Super FREQ
Posts: 375

Re: Explanation of %sysfunc in macro

[ Edited ]
Posted in reply to Suvrojoti

The macro language processes text.  If you want it to do something more, you have to tell it.

 

%let i = 1 + 2; * creates a string containing the numeral 1, a space, plus sign, space, and 2;

%let i = %eval(1 + 2); * creates a 3;

 

The %eval macro function says do the (integer) arithmetic.

So it is with %sysfunc.  That is how you say evaluate the SAS function; don't just assign the literal text as the value of a macro variable.

New Contributor
Posts: 3

Re: Explanation of %sysfunc in macro

Posted in reply to WarrenKuhfeld
@WareenKuhfeld thanks for your reply. I now understood how it is working. Similar for this statement %let dsid=%sysfunc(open(&mydata,i)); as you can see after &mydata we have an i. What is the utility of that?
Solution
4 weeks ago
SAS Super FREQ
Posts: 375

Re: Explanation of %sysfunc in macro

Posted in reply to Suvrojoti

http://go.documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n0q72zlfmfjplon1p3nprf85sdin.h...

 

It is an argument to the OPEN function.

 

opens the data set in INPUT mode (default). Values can be read but not modified. 'I' uses the strongest access mode available in the engine. That is, if the engine supports random access, OPEN defaults to random access. Otherwise, the file is opened in 'IN' mode automatically. Files are opened with sequential access and a system-level warning is set.

New Contributor
Posts: 3

Re: Explanation of %sysfunc in macro

Posted in reply to WarrenKuhfeld
Got it..many thanks..Smiley Happy
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 310 views
  • 1 like
  • 2 in conversation