BookmarkSubscribeRSS Feed
samuelw
Fluorite | Level 6

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.

 

 

 

 

3 REPLIES 3
Tom
Super User Tom
Super User

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.

 

Reeza
Super User

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. 

Kurt_Bremser
Super User
%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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1294 views
  • 5 likes
  • 4 in conversation