Parsing SYSPARM with infile magic
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 on the command line or in JCL when you start SAS.
options sysparm='value=37.2 start=01jan2006, end=01mar2006';
data _null_;
retain repeats 2.;
infile cards;
informat start end date9.;
input @;
_infile_ = translate(symget('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.

0 Comments:
Post a Comment
<< Home