DATA Step, Macro, Functions and more

Macro Value for SAS Program Name

Reply
N/A
Posts: 0

Macro Value for SAS Program Name

Hi,

I have been trying to put some code together as as standard macro to be included in all programs which are run. The code I am pulling together is essentially a complex proc printto with some automated checking built in to identify errors.

Is it running in a project environment with standard folder structures, but I was wondering if there is a macro variable which details your program name and/or the directory it is stored in (or a way to get this data). This would allow me to amend the code so that it would automatically save off without having to populate the macro with a folder and filename.

I hope this is clear enough and nay help would be greatly appreciated.
Contributor
Posts: 49

Re: Macro Value for SAS Program Name

You can get this inforrmation in a couple of ways (provided you're running in batch mode).

1. Use the SYSPROCESSNAME automatic macro variable
2. Use something like: %LET sysin=%SYSFUNC(GETOPTION(sysin));

Both of these give you the program name and path.
N/A
Posts: 0

Re: Macro Value for SAS Program Name

Thanks for the info, I have already looked at the automatic macro variables by running a %put _all_; and it never returned any value which looked appropriate.

I am running PC SAS locally on a windows environment, so I am not running it in a batch process.
Respected Advisor
Posts: 3,777

Re: Macro Value for SAS Program Name

See: http://support.sas.com/kb/8/707.html

This may help, but there are other issues with interactive submits this may not help with.
Super Contributor
Posts: 474

Re: Macro Value for SAS Program Name

OK Ian, no batch, then SYSPROCESSNAME is useless.
If your running in a interactive session, try looking into the DICTIONARY.EXTFILES table, that lists all external files opened in your session (including your scripts).
Your script should be listed there, you only have to find a logical manner to pick the right entry.

_data null_'s tip seems also a good solution, you should give it a try.

Greetings from Portugal.

Daniel Santos at www.cgd.pt.

> Thanks for the info, I have already looked at the
> automatic macro variables by running a %put _all_;
> and it never returned any value which looked
> appropriate.
>
> I am running PC SAS locally on a windows environment,
> so I am not running it in a batch process.
Super Contributor
Posts: 474

Re: Macro Value for SAS Program Name

Check for SAS Auto System Variables.

see: http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a003167023.htm

You might want to look into the &SYSPROCESSNAME Var

see: http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001221839.htm

Greeting from Portugal.

Daniel Santos at www.cgd.pt.
SAS Employee
Posts: 58

Re: Macro Value for SAS Program Name

Lawrence is correct. You can get this with &sysprocessname though if you want just the program name you need to clean it up a bit, e.g. the following is saved in a file named "mytestprogram.sas"...

1 %put &sysprocessname;
Program mytestprogram.sas
2
3 %let progname=%scan(&sysprocessname,2,%str( ));
4
5 %put &progname;
mytestprogram.sas
6

Note that when using the %scan() you must specify to use only a blank as a delimiter, and for this to work it must be enclosed within a %str( ).
Valued Guide
Posts: 2,174

Re: Macro Value for SAS Program Name

Iain

you're building a significant challenge, attempting to trap the names of "programs which are run". In the ad-hoc job submission worlds I have seen, the included program is often updated before it is "run", and in some cases the standard operating practises recommend not saving.
You may find a convenient trap available when code is submitted. Function keys and toolbar icons can be adapted to preform the trap you need.
You refer to proc printto. Have you recognised the potential of the alternative ALTLOG/ALTPRINT options? These leave your normal log and listing but send an additional copy to a file. Dynamically, you can identify and work with that file (but beware file locks which only a few applications like notepad.exe will ignore).
What would you want to do with the errors in a log which results from code which has not been saved and was created from new? No SAS feature can provide a name, because no name has been associated with that program!

good luck

PeterC
SAS Employee
Posts: 9

Re: Macro Value for SAS Program Name

The following SAS Usage note might also be helpful.

http://support.sas.com/kb/24/301.html
Ask a Question
Discussion stats
  • 8 replies
  • 268 views
  • 0 likes
  • 7 in conversation