BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MariaD
Barite | Level 11

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,

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Looks like your runsas command is NOT passing all of the command line parameters onto the actual call to SAS.

View solution in original post

9 REPLIES 9
Tom
Super User Tom
Super User

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.

Kurt_Bremser
Super User

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.

Patrick
Opal | Level 21

@MariaD

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.

https://support.sas.com/documentation/cdl/en/lesysoptsref/69799/HTML/default/viewer.htm#n16z79lqkz4a...

 

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"

MariaD
Barite | Level 11

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.

MariaD
Barite | Level 11

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,

nbonda
Obsidian | Level 7

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;

 

Tom
Super User Tom
Super User

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
MariaD
Barite | Level 11

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,

Tom
Super User Tom
Super User

Looks like your runsas command is NOT passing all of the command line parameters onto the actual call to SAS.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 17845 views
  • 3 likes
  • 5 in conversation