- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have 2 sas programs:
1. D:\SAS\main.sas
%include "run.sas";
2. D:\SAS\run.sas
%let outputfile = %qsubstr(%sysget(SAS_EXECFILEPATH),1, %length(%sysget(SAS_EXECFILEPATH))-4) ;
dm 'log; file "&outputfile..log" replace ';
dm 'log; clear';
If I run the run.sas separately without using %include, I can create run.log file. But if I call run.sas using main.sas then I get main.log instead.
I need to call run.sas from main.sas using %include and need to create run.log.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What happens if you try to overwrite the value of that environment variable in main.sas?
options set=SAS_EXECFILEPATH "run.sas";
%include "run.sas";
Note that your code is not very portable.
Your code is using Display Manager commands, so it can never be run like a normal SAS program, only from an interactive session that is using Display Manager.
Your code is referencing SAS_EXECFILEPATH which is an environment variable set by the Enhanced Editor on the PC implementation of SAS Display Manager. So even if you were running on SAS Display Manger, but you were using the regular program editor instead (only editor available on Unix versions of SAS) or using Notepad editor then it wouldn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A simpler design might be to make the current directory where you want the logs to go.
* main program ;
x "cd path";
%include "run.sas";
* run.sas ;
dm 'log; file "run.log" replace ';
dm 'log; clear';
You could try to figure out what directory to change to based on the value of SAS_EXECFILEPATH. But watch out for paths that are on a different mapped drive letter. Or are using UNCs (\\servername\sharename\....).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
HI Tom, thank you so much for your reply. Both of your methods need a line to be added before %include. Here I will run a series of run.sas, like
%include "run1.sas";
%include "runA.sas";
%include "run2.sas";
%include "run45.sas";
So, I need a dynamic variable which can capture the file name which is being called not file name that is calling it.
And, yes I am using SAS 9.4 editor in which "dm" is supported. I would like to know the alternative of dm if I need to run it other than Display Manager.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you need to keep logs of the code you run you should be running the programs from the command line instead running in interactive SAS. THen the log will have ALL of the SAS session and avoid issues with code running differently because of left over effects from previous code.
Open a command window and move to the folder where the programs are saved.
At the command line type the command SAS followed by the name of the program you want to run. You could group a bunch of commands together into a .BAT file.
sas "run1.sas" sas "runA.sas" sas "run2.sas" sas "run45.sas"
If your search path in windows does not know how to find the SAS command then either add the directory to the search path or use the fully qualified name of the SAS executable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Automatic macro variables can be used to solve it.
sysincludefiledir
sysincludefilename
sysincludefiledevice
sysinculdefileref