Help using Base SAS procedures

SYSPARM - Pass Command Line Arguments to SAS

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

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


Accepted Solutions
Solution
‎08-30-2017 01:21 PM
SAS Employee
Posts: 7

Re: SYSPARM - Pass Command Line Arguments to SAS

Posted in reply to ChrisMeaney

You can add the SYSPARM option to your command like this:

 

sas.exe -sysin C:\Users\meaneych\Desktop\BATCH_SAS_test\batch_sas_test.sas -sysparm '5 7 123456789'

 

Then in your SAS session you can do the following to separate the values passed with SYSPARM.  In this case the first value is mu, 2nd is variance and 3rd is seed.

 

%let mu=%scan(&sysparm,1);                  
%let variance=%scan(&sysparm,2);            
%let seed=%scan(&sysparm,3);                
                                            
data test.dat_mu&mu._var&variance. ;        
 do i = 1 to 12;                            
  x = &mu + sqrt(&variance)*rannor(&seed) ; 
  output ;                                  
 end ;                                      
run ;                                       

View solution in original post


All Replies
Regular Contributor
Posts: 227

Re: SYSPARM - Pass Command Line Arguments to SAS

Posted in reply to ChrisMeaney

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: 467

Re: SYSPARM - Pass Command Line Arguments to SAS

Posted in reply to ChrisMeaney

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

Posted in reply to PaulHomes

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: 4,237

Re: SYSPARM - Pass Command Line Arguments to SAS

Posted in reply to ChrisMeaney
Solution
‎08-30-2017 01:21 PM
SAS Employee
Posts: 7

Re: SYSPARM - Pass Command Line Arguments to SAS

Posted in reply to ChrisMeaney

You can add the SYSPARM option to your command like this:

 

sas.exe -sysin C:\Users\meaneych\Desktop\BATCH_SAS_test\batch_sas_test.sas -sysparm '5 7 123456789'

 

Then in your SAS session you can do the following to separate the values passed with SYSPARM.  In this case the first value is mu, 2nd is variance and 3rd is seed.

 

%let mu=%scan(&sysparm,1);                  
%let variance=%scan(&sysparm,2);            
%let seed=%scan(&sysparm,3);                
                                            
data test.dat_mu&mu._var&variance. ;        
 do i = 1 to 12;                            
  x = &mu + sqrt(&variance)*rannor(&seed) ; 
  output ;                                  
 end ;                                      
run ;                                       
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 9289 views
  • 3 likes
  • 6 in conversation