SyntaxHighlighter

Tuesday, June 25, 2013

SYSPARM Name=Value Pairs

The -SYSPARM option adds flexibility when invoking a SAS program in batch mode. According to SAS documentation, the quoted string can be up to 200 characters in length and can obtained by using the &sysparm macro variable, or sysparm() function.

The below macro was created to parse comma seperated name=value pairs passed to SAS via a SYSPARM string such as the following batch job example:

"sas.exe" -sysin "myprog.sas" -sysparm "mode=dev,date=20130625"

%macro sysparmpairs() ;
  %local i pair name ;

    %let i = 1 ;
    %do %while( %scan( %bquote( &sysparm. ), &i  ) ne %str() ) ;
      %let pair = %scan( %bquote(&sysparm.), &i  ) ;
      %let name = %scan(&pair,1,=) ;
      %global &name ;
      
      %let &name = %scan( &pair, 2, = ) ;
      %let i = %eval( &i + 1 ) ;
    %end ;
%mend ;

%sysparmpairs()

%put _user_ ;

GLOBAL DATE 20130625
GLOBAL MODE dev