Is it possible to extract the directory information based on where the SAS code is saved?
My current process is to manually define a macro for referrence. I would like to remove this manual process if the above is possible.
It really depends on how you are submitting the program.
If you have saved the program to a file and submitted the SAS command from the command line then the option SYSIN will have the program name. But it could be a relative name.
If you are using SAS Display Manager and have edited the file with the Enhanced Program Editor and saved it then SAS will have set an environment variable with the filename. But if you have not saved the program before submitting it or if you are using the normal Program Editor then that will not happen.
You need to add a lot more detail.
On this small amount, here's a guess at a solution. Use the following to get the path and then use the path in a %INCLUDE statement for your macro definition.
http://support.sas.com/kb/24/301.html
I'll usually design my project main program (control program) to take a main path parameter at the top, which is the path to the folder and then I use %include for several subfolders that can hold utitity macros, formats and other 'canned' code/processes I may need for a specific project.
%sysfunc(getoption(sysin))
will provide you the full path name of the program that is run in batch mode. At least it does so on AIX with SAS 9.4.
A full step to extract the path without the program name looks like this:
data _null_;
length path path2 $200;
path = getoption('sysin');
do i = 1 to countw(path,'/') - 1;
path2 = cat(strip(path2),'/'!!scan(path,i,'/'));
end;
put path2=;
run;
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.