Hi All - I am looking for a global macro variable which should be able to detect my current program path. I would like to add this to my autoexec file and call the macro in the SAS program. Can someone please help me?
%global variable_name;
%let variable_name = path;
save this in the autoexec file. You would be able to use the macro variable in the sas code that will resolve to the path.
I hope it helps.
Thanks for your response, but this way I have to define many macro variables in the autoexec file. I am looking for something which should be able to detect the program path and I want to use this in many other SAS programs. Is there any option in SAS which will be able to detect the current program path?
The reason I am looking for this option is because I can use relative path to call other SAS programs.
%include '¤tpath\..\..test.sas';
You may be looking for the SAS environment variable SAS_EXECFILEPATH if you are looking for the location of the sas code file.
You would get to that using %sysget(SAS_EXECFILEPATH) this returns the path AND the program file name. It assumes the program file has been saved before the %sysget() is executed.
This could be in any code file it need not be in the autoexec.sas (in fact you wouldn't want it as it there would have the location of the autoexec!)
Something like this perhaps:
%let workpath=%sysfunc(pathname(work));
At startup Base SAS usually defaults to the work library location.
You may use SYSPROCESSNAME.
Hope this helps,
- Jan.
What do you mean by "current program"? How did you submit the program.
If you issued started SAS from the command line then the SYSIN option should have the name of the program you are running.
Otherwise is is very difficult for SAS to know how you submitted the program.
Some have suggested using the environment variable (SAS_EXECFILEPATH) that the enhanced program editor sets. That might work some times IF you are using PC-SAS and IF you are using the enhanced program editor (instead of the many other ways to edit and/or submit SAS code in PC-SAS) and IF you happened to save the program before submitting it.
Current program refers to the program which I am executing in SAS EG interface.
I am submitting the program from SAS EG.
I am using the below code to get the sas program path, but this works only from DMS SAS, and does not work from SAS EG.
%macro pathfind;
%sysget(SAS_EXECFILEPATH)
%mend pathfind;
%put %pathfind;
From SAS EG, I get the below warning message,
WARNING: The argument to macro function %SYSGET is not defined as a system variable.
SAS_EXECFILEPATH is an environment variable set on your PC by the Enhanced Editor in PC-SAS. Not surprisingly it will not be set if you submit your program from Enterprise Guide.
You could submit a simple program to look at all macro variables.
%put _ALL_;
And environment variables (if you are allowed to use PIPEs).
data _null_;
set 'env' pipe;
input;
put _infile_;
run;
And looks around and see if Enterprise Guide has left any bread crumbs you can follow home.
But since your Enterprise Guide projects live on your PC and not on the server where SAS is running. Also also since the SAS programs live inside the project and not as .sas files on the file system I really doubt you will find any crumbs that the birds have not already eaten.
Thank You Tom. Looks like, there is no way I can get the program path name from SAS EG. I will look for other options.
Hi All - I found a sasnote which says that I can use _SASPROGRAMFILE from SAS EG/Studio to retrieve the filename/path. I am using the below statmenet
%put %sysget(_SASPROGRAMFILE);
but getting the message saying that as below.
WARNING: The argument to macro function %SYSGET is not defined as a system variable.
Do I need to define %sysget as a system variable? I am connecting to a SAS server running on windows OS.
Late reply but here we go. Hopefully this helps someone in the future :
SAS Windows environment maintains the SAS OPTION of SAS_EXECFILEPATH as the location of the SAS file that you are running.
SAS EG keeps the file path and program name logged in its systems macro variables. The path would be housed in &_SASPROGRAMFILE
To assign these values in a macro variable you could do :
1. %let New_path=%sysfunc(dequote(&_SASPROGRAMFILE)); /*----Enterprise Guide-----*/
2. %let New_path=%sysget(SAS_EXECFILEPATH); /*----SAS Windows Environment-----*/
Bonus: If you run SAS is batch mode using a BAT. file to open SAS and call the program you want, the input changes to SYSIN when you use the window CMD language "sysin" to call the file :
3. %let New_path=%sysfunc(getoption(SYSIN));
Note that the SAS_EXECFILEPATH environment variable is not really very reliable.
It only works in the "enhanced" editor, not the normal Display Manager program editor window that works in all versions of SAS. And then it only knows what name you last used for the file. You might not have ever saved the file. You might have modified that file and not saved the changes.
7 * Regular program editor ; 8 %put SAS_EXECFILE=%sysget(SAS_EXECFILEPATH); SAS_EXECFILE= 9 * Enhanced editor, file saved ; 10 %put SAS_EXECFILEPATH=%sysget(SAS_EXECFILEPATH); SAS_EXECFILEPATH=C:\downloads\test1.sas 11 * Enhanced editor, file not save yet ; 12 %put SAS_EXECFILEPATH=%sysget(SAS_EXECFILEPATH); SAS_EXECFILEPATH=
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.