Desktop productivity for business analysts and programmers

Extract the directory information based on where the SAS code is saved

Reply
Occasional Contributor
Posts: 5

Extract the directory information based on where the SAS code is saved

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.

 

 

 

 

Super User
Super User
Posts: 8,272

Re: Extract the directory information based on where the SAS code is saved

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.

 

Super User
Posts: 23,980

Re: Extract the directory information based on where the SAS code is saved

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. 

Super User
Posts: 10,535

Re: Extract the directory information based on where the SAS code is saved

%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;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 3 replies
  • 378 views
  • 5 likes
  • 4 in conversation