From: Jack Hamilton on 14 Apr 2006 02:51 <http://www.excursive.com/sas/weblog/2006/04/parsing-sysparm-with-infile-magic.html> Here's a method of using "infile magic" to parse the value of the &SYSPARM macro variable, which is valued by setting the SYSPARM system option, typically at execution. options sysparm='value=37.2 start=01jan2006, end=01mar2006'; data _null_; retain repeats 2.; infile cards; informat start end date9.; input @; _infile_ = translate("&SYSPARM.", ' ', ','); input start= end= value= repeats=; format start end date9.; put (_all_) (=); stop; cards; ;;;; prints: start=01JAN2006 end=01MAR2006 value=37.2 repeats=2 A few comments: * The separator has to be a blank for named input. Commas are translated into blanks because under MVS a comma will appear in the value of SYSPARM if you use JCL continuation when specifying SYSPARM. This will, of course, present difficulties if you need to have a comma in one of your values. * You can assign a default value to a parameter by establishing its value before the INPUT statement. In this case, I used the RETAIN statement to set the value. * The parameters can appear in any order. Unfortunately, you can't tell (without reparsing the data) which order they did appear in. * If you include in SYSPARM a variable which does not appear in the INPUT statement, you'll get a note in the log and _ERROR_ will be set to 1. * In real life, you'd want to save the values somewhere, either in a SAS data set or with CALL SYMPUT/SYMPUTX.
|
Pages: 1 Prev: Help to open sasmacr.sas7bcat file Next: calculate variance |