As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Difference between revisions of "Parse sysparm"

From sasCommunity
Jump to: navigation, search
m
m (polishing: changed pre to source, added categories)
Line 1: Line 1:
<pre>
+
Q: How can I pass multiple named values to a program?
%*parse-sysparm.sas;
+
 
 +
A: use command-line or sas statement option sysparm
 +
with comma-separated values.
 +
 
 +
* batch: command-line option: ''-sysparm 'value'''
 +
* program: option statement: ''options sysparm = 'value';''
 +
 
 +
<source lang="sas">
 +
/*   name: parse-sysparm.sas
 +
description: parse the text in option sysparm into macro variables
 +
    purpose: support batch processing command-line parameter passing
 
;/* testing in program ****** **
 
;/* testing in program ****** **
 
options source2;%* for put _global_;
 
options source2;%* for put _global_;
Line 6: Line 16:
 
;/***** ********************* */
 
;/***** ********************* */
  
DATA   _Null_;
+
DATA _Null_;
attrib Stmnt  length = $132
+
    attrib Stmnt  length = $132
      Testing length =    4;
+
            Testing length =    4;
retain Testing %eval(0
+
    retain Testing %eval(0
      or "%sysfunc(getoption(Source2))"
+
            or "%sysfunc(getoption(Source2))"
                          eq "SOURCE2"
+
                              eq "SOURCE2"
      or "%sysfunc(getoption(Verbose))"
+
            or "%sysfunc(getoption(Verbose))"
                          eq "VERBOSE"  );
+
                              eq "VERBOSE"  );
 
if "&SysParm." ne "" then do;
 
if "&SysParm." ne "" then do;
 
   putlog "SysParm: &SysParm.";
 
   putlog "SysParm: &SysParm.";
Line 29: Line 39:
 
   end; %*if "&SysParm." ne "";
 
   end; %*if "&SysParm." ne "";
 
stop;
 
stop;
run;    %*calls execute here;
+
run;    *calls execute here;
 
run;
 
run;
</pre>
+
</source>
 +
 
 +
-- created by [[User:Rjf2]] 10:22, 14 June 2007 (EDT)
 +
 
 +
--[[User:Ron.Fehd.macro.maven|Ronald_J._Fehd macro.maven == the radical programmer]]
  
--macro maven == the radical programmer 10:22, 14 June 2007 (EDT)
+
[[Category:Macros_by_Ron_Fehd]]
 +
[[Category:Passing_Values]]
 
[[Category:SAS Code]]
 
[[Category:SAS Code]]
 
[[Category:Sysparm]]
 
[[Category:Sysparm]]
 
[[Category:Testing]]
 
[[Category:Testing]]

Revision as of 14:53, 20 July 2012

Q: How can I pass multiple named values to a program?

A: use command-line or sas statement option sysparm with comma-separated values.

  • batch: command-line option: -sysparm 'value'
  • program: option statement: options sysparm = 'value';
 /*    name: parse-sysparm.sas
description: parse the text in option sysparm into macro variables
    purpose: support batch processing command-line parameter passing
;/* testing in program ****** **
options source2;%* for put _global_;
options sysparm = 'a=1;b=2;d=4';
;/***** ********************* */
 
DATA _Null_;
     attrib Stmnt   length = $132
            Testing length =    4;
     retain Testing %eval(0
            or "%sysfunc(getoption(Source2))"
                               eq "SOURCE2"
            or "%sysfunc(getoption(Verbose))"
                               eq "VERBOSE"  );
if "&SysParm." ne "" then do;
   putlog "SysParm: &SysParm.";
   do I = 1 to %*number of equal-signs;
          length(compress("&SysParm",'=','k'));
      Stmnt= catx(' ' %*separated by space;
                 ,'%let '
                 ,scan("&SysParm.",I,';')
                 ,';');
      if   Testing then putlog Stmnt=;
      call execute(cat('%nrstr(',Stmnt,')'));
      end; %*do I;
   if Testing then
      call execute('%nrstr(%put _global_;)');
   end; %*if "&SysParm." ne "";
stop;
run;    *calls execute here;
run;

-- created by User:Rjf2 10:22, 14 June 2007 (EDT)

--Ronald_J._Fehd macro.maven == the radical programmer