- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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?