- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
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,
Regards,
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Looks like your runsas command is NOT passing all of the command line parameters onto the actual call to SAS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you have lots of parameters to pass, use environment variables:
(shell script)
export VAR1=val1 export VAR2=val2 /sasconf/Lev1/SASApp/BatchServer/sasbatch.sh /path/program.sas
(program)
%let var1=%sysget(VAR1);
%let var2=%sysget(VAR2);
/* code */
This keeps the SAS commandline clean. Use it to pass configuration options, not program parameters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Patrick,
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.
&prog
9
10 %put &usuario;
WARNING: Apparent symbolic reference USUARIO not resolved.
&usuario
Any suggestion?
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
data _null;
_value1=scan(sysparm(),1,', ');
_value2=scan(sysparm(),2,',');
call symput("value1", "_value1");
call symput("value2", "_value2");
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need to post your code.
If you run a program that consists of the just the line.
%put _user_;
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Tom,
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
3
4 /* Verifica Fecha de Inicio */
5 %let Fecha_Inicio = %sysfunc(datetime(), datetime19.);
6
7 /* Define programa a agendar en Crontab */
8 %put _user_;
GLOBAL FECHA_INICIO 19JUN2017:13:42:39
GLOBAL SYSDBMSG
GLOBAL SPDS_CLIENT_COMPILED Mar 25 2010
Any idea why?
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Looks like your runsas command is NOT passing all of the command line parameters onto the actual call to SAS.