DATA Step, Macro, Functions and more

Global Macro Variable

Reply
Contributor
Posts: 70

Global Macro Variable

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?

Occasional Contributor
Posts: 19

Re: Global Macro Variable

%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.

Contributor
Posts: 70

Re: Global Macro Variable

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?

Contributor
Posts: 70

Re: Global Macro Variable

The reason I am looking for this option is because I can use relative path to call other SAS programs.

 

%include '&currentpath\..\..test.sas';

Super User
Posts: 10,552

Re: Global Macro Variable

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!)

Super User
Posts: 10,552

Re: Global Macro Variable

Something like this perhaps:

 

%let workpath=%sysfunc(pathname(work));

 

At startup Base SAS usually defaults to the work library location.

 

 

Super Contributor
Posts: 408

Re: Global Macro Variable

You may use SYSPROCESSNAME.

 

Hope this helps,

- Jan.

Super Contributor
Posts: 408

Re: Global Macro Variable

You will have to parse out the value.

If I run

sas /home/jan/test.sas

then I get

SYSPROCESSNAME=Program /home/jan/test.sas
Super User
Super User
Posts: 6,502

Re: Global Macro Variable

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.

Contributor
Posts: 70

Re: Global Macro Variable

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.

 

Super User
Super User
Posts: 6,502

Re: Global Macro 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.

Contributor
Posts: 70

Re: Global Macro Variable

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.

Contributor
Posts: 70

Re: Global Macro Variable

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.

 

http://support.sas.com/kb/24/301.html

Ask a Question
Discussion stats
  • 12 replies
  • 681 views
  • 4 likes
  • 5 in conversation