BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
8 REPLIES 8
LawrenceHW
Quartz | Level 8
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.
deleted_user
Not applicable
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.
data_null__
Jade | Level 19
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.
DanielSantos
Barite | Level 11
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.
DanielSantos
Barite | Level 11
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.
PatrickG
SAS Employee
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( ).
Peter_C
Rhodochrosite | Level 12
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
Russ_SAS
SAS Employee
The following SAS Usage note might also be helpful.

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

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 8 replies
  • 1740 views
  • 0 likes
  • 7 in conversation