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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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