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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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