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
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 ;
Here are two pages to get you started
Batch processing under Windows - 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;
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;
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
See the article "How to pass parameters to a SAS program."
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 ;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.