Start and override SAS code program/macro variables from command line

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Start and override SAS code program/macro variables from command line

Does the SAS command line command have an option to override a SAS variable?

 

SAS Code in run_sas_code.sas

%let my_path=/default/path/;
%put &my_path.;

Command line command:

sas /home/users/me/run_sas_code.sas -log /home/users/me/log.log

I want something like that:

sas /home/users/me/run_sas_code.sas -log /home/users/me/log.log --my_path=/new/path/value/

 

Thanks!


Accepted Solutions
Solution
‎05-08-2017 08:49 AM
Esteemed Advisor
Posts: 6,640

Re: Start and override SAS code program/macro variables from command line

When you use -sysparm= on the commandline, the text following the -sysparm= will be available in automatic macro variable &sysparm in the SAS session. Note that you can't change the name of the macro variable.

A more flexible way for handing parameters to batch programs is the use of operating system environment variables. Consider this shell script:

export VAR1=xxxxxx
export VAR2=yyyyy
sas program.sas

and this program:

%let var1=%sysget(VAR1);
%let var2=%sysget(VAR2);

data mylib.test;
var1 = "&var1";
var2 = "&var2";
run;

You will find the contents ("xxxxxx" and "yyyyy") in dataset mylib.test.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Trusted Advisor
Posts: 1,492

Re: Start and override SAS code program/macro variables from command line

If you want to change the value of a macro variable, you can do so in the AUTOEXEC file, and then it will apply to the entirety of your SAS session; alternatively you could change the value of the macro variable in the first command of your SAS session.

Occasional Contributor
Posts: 8

Re: Start and override SAS code program/macro variables from command line

Thanks.
But i want to start sas from an other software via command line. I do not want to modify or customize the SAS files. I guess, however, that I must exchange the .sas file before the run once.


Or is there a way to start the SAS file in an existing session?
Solution
‎05-08-2017 08:49 AM
Esteemed Advisor
Posts: 6,640

Re: Start and override SAS code program/macro variables from command line

When you use -sysparm= on the commandline, the text following the -sysparm= will be available in automatic macro variable &sysparm in the SAS session. Note that you can't change the name of the macro variable.

A more flexible way for handing parameters to batch programs is the use of operating system environment variables. Consider this shell script:

export VAR1=xxxxxx
export VAR2=yyyyy
sas program.sas

and this program:

%let var1=%sysget(VAR1);
%let var2=%sysget(VAR2);

data mylib.test;
var1 = "&var1";
var2 = "&var2";
run;

You will find the contents ("xxxxxx" and "yyyyy") in dataset mylib.test.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 8

Re: Start and override SAS code program/macro variables from command line

I've been looking for that. Many Thanks.
SAS Super FREQ
Posts: 3,390

Re: Start and override SAS code program/macro variables from command line

For a discussion and example, see "How to pass parameters to a SAS Program."

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 166 views
  • 1 like
  • 4 in conversation