%SYSFUNC

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

%SYSFUNC

Hello,

How to use %SYSFUN. It seems used in almost every code I can find on the web, but still, I found poor documentation about it. A hand here to understand what does %SYSfunc will be useful.

Thanks


Accepted Solutions
Solution
‎08-29-2016 05:02 AM
Super Contributor
Posts: 266

Re: %SYSFUNC

In one sentence, sysfunc help to execute data step function in sas macros. For more details 

 

Refer to section

USING DATA STEP FUNCTIONS IN THE MACRO LANGUAGE

from this link   http://www2.sas.com/proceedings/sugi25/25/aa/25p004.pdf

 

 

View solution in original post


All Replies
Solution
‎08-29-2016 05:02 AM
Super Contributor
Posts: 266

Re: %SYSFUNC

In one sentence, sysfunc help to execute data step function in sas macros. For more details 

 

Refer to section

USING DATA STEP FUNCTIONS IN THE MACRO LANGUAGE

from this link   http://www2.sas.com/proceedings/sugi25/25/aa/25p004.pdf

 

 

Super User
Posts: 7,764

Re: %SYSFUNC

%sysfunc() allows one to use SAS data step functions outside of a data step in macro language.

Everything important can be found in the SAS docs about this function:

%SYSFUNC and %QSYSFUNC Functions

The more important question: what do you intend to do with it?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 11,343

Re: %SYSFUNC

Posted in reply to KurtBremser

+1 on @KurtBremser's question about what are you attempting. If you are finding so many references to %Sysfunc I suspect that you are searching for macros. Frequently new SAS users attempt macros because they think they need to and end up creating complicated code because they have involved macros in a suboptimal approach to a problem. Repeated use of %Sysfunc is sometimes a symptom of not using the best tool for the job.

 

Even when I am writing macros I don't frequently use %sysfunc. I don't think I've used %sysfunc this month and I've probably written about 3500 debugged lines of code this month.

Occasional Contributor
Posts: 15

Re: %SYSFUNC

I am for the simplest , the most optimal approach too. 

proc transpose name=varname label=vlabel data=allvar out=allvar1;
   var &all_vars %sysfunc(
                             ifc(
                                 %superQ(allvar) eq,%nrstr(_all_),%nrstr()
                              )
                              );
   run; 

Is there a way to substitute this part of the code, without using %sysfunc and ifc? ( by the way ifc does not work in some framework settings) 

Super User
Posts: 7,764

Re: %SYSFUNC


Milouda wrote:

I am for the simplest , the most optimal approach too. 

proc transpose name=varname label=vlabel data=allvar out=allvar1;
   var &all_vars %sysfunc(
                             ifc(
                                 %superQ(allvar) eq,%nrstr(_all_),%nrstr()
                              )
                              );
   run; 

Is there a way to substitute this part of the code, without using %sysfunc and ifc? ( by the way ifc does not work in some framework settings) 


Take another approach: What is proc transposed supposed to do here? Then you can ask yourself how to go about it.

Don't start worrying about methods; think about goals first, then consider the methods suited to achieve them.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 15

Re: %SYSFUNC

Posted in reply to KurtBremser
I am trying to understand what this particular lines of code return:
%sysfunc(
ifc(
%superQ(allvar) eq,%nrstr(_all_),%nrstr()
)
);
Note: ALLVAR is a dataset
Super User
Posts: 7,764

Re: %SYSFUNC


Milouda wrote:
I am trying to understand what this particular lines of code return:
%sysfunc(
ifc(
%superQ(allvar) eq,%nrstr(_all_),%nrstr()
)
);
Note: ALLVAR is a dataset

In this context, allvar is not a dataset, but a macro variable. %superq takes the contents of the macro variable supplied as its argument, masks all macro triggers, and writes that as its result.

What happens is that the condition

(contents of &allvar) eq (empty string)

is evaluated; if allvar is empty, it is substituted by the text _all_ (otherwise another empty string), so that if no variable names are supplied in &allvar, the procedure will work on all variables in the input dataset.

The fact that such a short piece of code lets you wonder what it is supposed to do, illustrates one of the dangers of macro programming (and "clever" programming generally).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 555 views
  • 4 likes
  • 4 in conversation