BookmarkSubscribeRSS Feed
bhu
Obsidian | Level 7 bhu
Obsidian | Level 7

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.

5 REPLIES 5
Tom
Super User Tom
Super User

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.

Tom
Super User Tom
Super User

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\....).

bhu
Obsidian | Level 7 bhu
Obsidian | Level 7

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.

Tom
Super User Tom
Super User

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.

 

whymath
Lapis Lazuli | Level 10

Automatic macro variables can be used to solve it.

sysincludefiledir

sysincludefilename

sysincludefiledevice

sysinculdefileref

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 5169 views
  • 0 likes
  • 3 in conversation