06-16-2017 02:06 PM
I'm trying to pass a parameters for a SAS code that is executed on command line (using crontab).
I've just tried the following options but nothing happens:
sas /<path>/<program>.sas -set p1 value1 -set p2 value2
sas /<path>/<program>.sas -sysparm "p1=value1,p2=value2"
Inside the <program>.sas I use proc printto to redirect the log. When running only sas /<path>/<program>.sas the program execute and generate the corresponding SAS log. When trying to execute the "-set" version or "-sysparm" version, SAS log file is not generated and nothing happen.
Any idea what's going on? I'm executing on Unix (HP-UX) and with SAS 9.2 TSM2 version,
06-16-2017 09:34 PM
On a Unix command the options come before the arguments.
sas -set p1 value1 -set p2 value2 /<path>/<program>.sas
You can also use the -sysin option to specify the program name, but I am not sure why anyone would use that.
06-17-2017 03:34 AM
If you have lots of parameters to pass, use environment variables:
export VAR1=val1 export VAR2=val2 /sasconf/Lev1/SASApp/BatchServer/sasbatch.sh /path/program.sas
%let var1=%sysget(VAR1); %let var2=%sysget(VAR2); /* code */
This keeps the SAS commandline clean. Use it to pass configuration options, not program parameters.
06-17-2017 11:38 PM - edited 06-17-2017 11:54 PM
Besides of -SET which creates OS environment variables you can also use option -INITSTMT and then have a few %LET statements which create macro variables which you can use directly in your code.
I normally prefer to implement a permanent parameter table and then call this table from my code. This allows me to see everything that's going on directly in the code and also to change parameter values in data instead of having to change code.
I also tend to use sas.sh for batch commands as this will invoke the full application server specific environment with all the .cfg's and autoexec's I've used for developing my code (i.e. .../Config/Lev1/SASApp/sas.sh )
I use proc printto to redirect the log
Why? You can pass in parameters -LOG and -PRINT to define where your output goes. And you can use date and time directives for your log and output so you'll get individually named logs per batch execution.
Here an example how this could look like (and yes, I prefer to use -sysin as then I can list the .sas file wherever I want).
..../Config/Lev1/SASApp/sas.sh -sysin ".../test/HelloWorld.sas" -log ".../test/#P_#Y#m#d_#H#M#s_#p.log"
06-19-2017 10:33 AM
Thanks @Patrick. I'll try -INITSTMT now and let you know. I prefer working with parameter's tables too. IIn this particulary case, the process will be controled by staff does not have SAS knowledged (TI support), so I'm trying to solve it with minimum changes needed and where the change will be implemented in the same command line.
06-19-2017 11:42 AM
I've just run the following example:
sas /<path>/<program>.sas -initstmt '%let prog=Program1; %let usuario= Natalia UserName;'
After the execution, the following warning appears in log:
8 %put &prog;
WARNING: Apparent symbolic reference PROG not resolved.
10 %put &usuario;
WARNING: Apparent symbolic reference USUARIO not resolved.
06-19-2017 12:14 PM
The -sysparm in you question should work, you can pass multiple parameters in -sysparm option and parse it using scan function in sas file. To redirect your log and lst result to particular file you can use -log and -print options.
Modifying your code as below:
sas /<path>/<program>.sas -sysparm "value1,value2" -log anypath/anyname.log -print anypath/anyname.lst
in your code you can parse -sysparm using scan function.
call symput("value1", "_value1");
call symput("value2", "_value2");
06-19-2017 12:46 PM
You need to post your code.
If you run a program that consists of the just the line.
Then your -initstmt method works great.
NOTE: SAS initialization used: real time 0.68 seconds cpu time 0.02 seconds 1 %put _user_; GLOBAL PROG Program1 GLOBAL USUARIO Natalia UserName NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414 NOTE: The SAS System used: real time 0.78 seconds cpu time 0.02 seconds
06-19-2017 02:03 PM
I've just run the following command line:
runsas /<path>/<program>.sas -initstmt '%let prog=/<path>/Program1.sas; %let usuario= Natalia;'
But in log, the parameters prog and usuario are not showing:
NOTE: PROCEDURE PRINTTO used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
4 /* Verifica Fecha de Inicio */
5 %let Fecha_Inicio = %sysfunc(datetime(), datetime19.);
7 /* Define programa a agendar en Crontab */
8 %put _user_;
GLOBAL FECHA_INICIO 19JUN2017:13:42:39
GLOBAL SPDS_CLIENT_COMPILED Mar 25 2010
Any idea why?
Need further help from the community? Please ask a new question.