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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

 

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
StoneCat
Fluorite | Level 6
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?
Kurt_Bremser
Super User

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.

 

StoneCat
Fluorite | Level 6
I've been looking for that. Many Thanks.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 2135 views
  • 1 like
  • 4 in conversation