DATA Step, Macro, Functions and more

How to get the name of program being executed in SAS EG 6.1

Reply
Frequent Contributor
Posts: 79

How to get the name of program being executed in SAS EG 6.1

[ Edited ]

Hi ALL,

 

I am trying to use the below code to export my log from SAS Enterprise Guide 6.1 to a specified location based on the program name?

 

So basically i want to find out the program name so that i can put the below code in the SAS enterprise guide

Option->sas programs ->Additional sas code ->Insert custom SAS code before submitted code

 

We have a grid environment, where we are using a Linux server to execute the code and frontend is SAS EG 6.1


%let Name = TEST1;
%let pgm_name = /* need help here */;
%let today= %sysfunc(putn(%sysfunc(today()),yymmddn8.));

proc printto  log = "/sas/develop/admin/&name./dev/logs/&pgm_name._&today..txt" new;
run;

i have tried many ways, but could not find any for doing this in interactive mode.

 

 

Thanks in Advance,

 

Manjeet


Cheers from India!

Manjeet
New Contributor
Posts: 4

Re: How to get the name of programming being executed in SAS EG 6.1

%macro pgmname() ;

   %local retval ;

   %let retval = %sysfunc( getoption( sysin ) ) ; /* batch mode */

   %if %isblank( &retval. ) %then %let retval = &_SASPROGRAMFILE ; /* interactive mode */

   /* next line removes single quotes produced in interactive mode */

   %qsysfunc( compress( &retval., %str(%') ) )

%mend ;

Super User
Super User
Posts: 7,844

Re: How to get the name of programming being executed in SAS EG 6.1

Posted in reply to tbellmer_wf

What????


tbellmer_wf wrote:

 


...

   /* next line removes single quotes produced in interactive mode */

   %qsysfunc( compress( &retval., %str(%') ) )

... 


Why would you want to remove ALL of the quotes from a string?  Wouldn't that make any string that includes quotes invalid?

Are you trying to remove the outer quotes around the string?

%qsysfunc(dequote(&retval.))

 

New Contributor
Posts: 4

Re: How to get the name of programming being executed in SAS EG 6.1

Feel free to modify as you desire. I needed to do that for my purposes.
Frequent Contributor
Posts: 79

Re: How to get the name of programming being executed in SAS EG 6.1

Posted in reply to tbellmer_wf
@tbellmer_wf thanks for the help.

However the &_SASPROGRAMFILE variable doesn't exist in the SAS Eg. So this code won't help.

Cheers from India!

Manjeet
New Contributor
Posts: 4

Re: How to get the name of programming being executed in SAS EG 6.1

Oh but it actually does as I use this all the time. Apparently there are a few caveats so be sure to read this note: http://support.sas.com/kb/59/744.html
Regular Contributor
Posts: 195

Re: How to get the name of programming being executed in SAS EG 6.1

Take care to backup the code you added to EG options. Afaik the code is stored somewhere in %userprofile% directory, so if those directories aren't backuped all code is lost when the hard disk dies.

@tbellmer_wf are you sure, that _sysprogramfile exists in EG-sessions? Thought that this variable is only created in Studio, batch and display-manager sessions.
Frequent Contributor
Posts: 79

Re: How to get the name of programming being executed in SAS EG 6.1

Posted in reply to error_prone

@error_prone - you are right, the &_SASPROGRAMFILE variable doesn't exist in SAS Eg interactive mode. We have to search for other options.

 

Thanks for the help!


Cheers from India!

Manjeet
Regular Contributor
Posts: 195

Re: How to get the name of programming being executed in SAS EG 6.1

[ Edited ]

Afaik no variable holding the program-name exists. The variable _ClientProjectPath has name and path of the EG-project. If you are using macros SysMacroName has the name of macro being executed, there could be a function returning the path of the macro. Can't verify this right now.

Super User
Posts: 10,610

Re: How to get the name of programming being executed in SAS EG 6.1

%let x=%sysget(sas_execfilename);
%let y=%sysget(sas_execfilepath);

%put &x ;
%put &y ;
Ask a Question
Discussion stats
  • 9 replies
  • 144 views
  • 4 likes
  • 5 in conversation