BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
stataq
Quartz | Level 8

Hello,

 

Please pardon me if this question is too silly.

 

I could run following code in interactive mode but got following warning in batch mode. Why? How can I run this in batch mode?

 %let _source=%sysget(sas_execfilepath);

WARNING: The argument to macro function %SYSGET is not defined as a system variable.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

You need set a parameter in batch file for it.Like:

"D:\SASHome\SASFoundation\9.4\sas.exe" -nosplash -sysin "c:\temp\temp.sas"  -set sas_execfilepath "c:\temp\temp.sas"

Or try GETOPTION() function:

%let path=%sysfunc(getoption(sysin));
%put &path.;

 

 

View solution in original post

6 REPLIES 6
Ksharp
Super User

You need set a parameter in batch file for it.Like:

"D:\SASHome\SASFoundation\9.4\sas.exe" -nosplash -sysin "c:\temp\temp.sas"  -set sas_execfilepath "c:\temp\temp.sas"

Or try GETOPTION() function:

%let path=%sysfunc(getoption(sysin));
%put &path.;

 

 

stataq
Quartz | Level 8

@Ksharp Could you further explain the part on "set a parameter in batch file"? 😅

 

I also tried "GETOPTION()". In my system, it get path in patch mode but not interactive mode.  Is it normal?

 

Is there a way to get path in both methods? 

Thanks.

Patrick
Opal | Level 21

sas_execfilepath is an environment variable set and updated when you're using "PC SAS".

If you're running in batch mode then SAS can't know in advance what program you want to run and though won't create this environment variable. 

The -set option in the batch command @Ksharp shared lets you define and populate an environment variable that you then can query within your program. This then allows you to execute the exactly same code in batch. 

Alternatively you can also query the value of SYSIN as it will also contain the path to the .sas file you're executing in batch.

Ksharp
Super User
"I also tried "GETOPTION()". In my system, it get path in patch mode but not interactive mode. Is it normal?"
Yes. It is normal.

"Is there a way to get path in both methods? "
Did you check my code ?
-set sas_execfilepath

@Rick_SAS wrote a blog about this before. Check:
https://blogs.sas.com/content/iml/2015/03/16/pass-params-sysget.html
Tom
Super User Tom
Super User

You will get that warning if you are not running interactively on Windows since that environment variable is only set by PC-SAS.

 

Example here is what I get when running interactive Display Manager on Unix.

WARNING: The argument to macro function %SYSGET is not defined as a system variable.
1    %put %sysget(sas_execfilepath);

2    %put %sysfunc(getoption(dms));
DMS
3    %put &=sysscp;
SYSSCP=LIN X64

If you are running from the command line (what some call "batch" mode even when there are no batch queues involved) then you probably want to get the value of the SYSIN option instead if the goal is to check what SAS program is being run.

Put this code into your program instead:

%let _source=%sysfunc(getoption(sysin));
stataq
Quartz | Level 8

@Tom @Ksharp @Patrick  Thanks so much for the kindly explanations. I am learning SAS for about 1 year, I was told that I should make all my programs batch runnable. Is it true that is how sas program should be? 

 

I normally develop my codes in interactive mode, and stuck when I tried to run them in batch mode. Any suggestion on how to make interactive mode code runnable in batch mode? what kind of modification I should do normally?  

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 274 views
  • 6 likes
  • 4 in conversation