Help using Base SAS procedures

SYSPARM - Pass Command Line Arguments to SAS

Reply
New Contributor
Posts: 3

SYSPARM - Pass Command Line Arguments to SAS

Hi. I am new to SAS Batch processing capabilities and SYSPARM functionality.

Say I have the following SAS program (batch_sas_test.sas). Basically a short program with 3 parameters (mu, variance and seed) that creates 12 random normal variates from a given normal distribution (specified by mu and vairance).

/** Libname to store simulated data **/

libname test "C:\Users\meaneych\Desktop\BATCH_SAS_test\" ;

run ;

%let mu = 5 ;

%let variance = 7 ;

%let seed=123456789 ;

data test.dat_mu&mu._var&variance. ;

do i = 1 to 12;

      x = &mu + sqrt(&variance)*rannor(&seed) ;

      output ;

end ;

run ;

On my system I can BATCH process the above program using Windows Command Prompt syntax.

sas.exe -sysin C:\Users\meaneych\Desktop\BATCH_SAS_test\batch_sas_test.sas

How do I extend my batch_sas_test.sas program using sysparm such that I can pass my mean/variance/seed parameters from the command line into the SAS program? Similarly, how would I update the Command Prompt syntax to pass these arguments into the SAS program?

Thanks

Chris

Regular Contributor
Posts: 203

Re: SYSPARM - Pass Command Line Arguments to SAS

Here are two pages to get you started

Batch processing under Windows - sasCommunity

Parse sysparm - sasCommunity

eventually you will create a batch file

- - - program-with-sysparm.bat - - -

sas program-with-sysparm -sysparm 'mean=1.01,variance=2.22,seed=33.0003'

- - - program-with-sysparm.sas


    %include site_inc(parse-sysparm);

    %put &=mean &=variance &=seed;

I am guessing that your parameters values are real numbers, not integers.

So any calculations you want to do with them in the macro language must be done with %sysevalf

    %let mean_plus_point_2 = %sysevalf(&mean +0.2);

    %put &=mean_plus_point_2;

PROC Star
Posts: 392

Re: SYSPARM - Pass Command Line Arguments to SAS

Another technique that avoid parsing the single value sysparm system option, at least on Windows and UNIX/Linux, is to use multiple -set command line options and get the values with %sysget

Here's an example. The progrtest.sas has:

%put %sysget(parm1);
%put %sysget(parm2);

... then run it with:

sas -set parm1 value1 -set parm2 "value2 has spaces" test.sas;
Occasional Contributor
Posts: 10

Re: SYSPARM - Pass Command Line Arguments to SAS

This is what finally worked for me on Windows 2012.

set sasparm=value
Start /WAIT "SAS_job" sas "C:\temp\test.sas" -log "C:\temp\test.log" -nosplash -nologo -noicon

SAS Super FREQ
Posts: 3,489

Re: SYSPARM - Pass Command Line Arguments to SAS

Ask a Question
Discussion stats
  • 4 replies
  • 5298 views
  • 2 likes
  • 5 in conversation