%include path

Reply
Super User
Super User
Posts: 7,430

%include path

Hi,

My scenario: I have one SAS program which when it opens writes the path to itself out to the log from sas_execfilepath/name.  Now, when within that program I %include other SAS programs, I would like to find the path/filename for the file included.  Is there in the metadata a store of includes/nesting?  I know that if /source is put at the end of the include statement then in the log it shows path/filename, however its too late to read that back in from the log as the code will have executed.  So:

MainProgram.sas     -> Path=C:\temp, Name=MainProgram.sas - stored in sas_execfilpath/name.

     -> %include "c:\temp\subfolder1\SubProgram1.sas"     -> Level 1 include, sas_execfilepath/name still point to the MainProgram.sas.

Am sure its captured in the SASHELP library somewhere but cant seem to find it.

Thanks

Super User
Posts: 9,691

Re: %include path

I don't think there is a metatdata stored in INCLUDE CODE .

But you can call execute to create a new macro to contain sas_execfilename "c:\temp\subfolder1\SubProgram1.sas" . Like :

MainProgram.sas


data _null_;

call execute(' data _null_; call symputx("sasexecfilename", "c:\temp\subfolder1\SubProgram1.sas"); run;');

call execute('%include "c:\temp\subfolder1\SubProgram1.sas" ');

run;

In SubProgram1.sas ,specify this kind of macro variable sasexecfilename :

%let sasexecfilename=  ;

.......your code..........

Xia Keshan

Super User
Super User
Posts: 7,430

Re: %include path

Hi,

Thank you Xia Keshan.  Yes, I will just have a switch at each stage that either sets to the system variable if macro variable is not present, or uses the one already created if present.  Seems a bit of a faf really, would have been nice to have a metadata table:

level          filepath

0               c:\mainprogram.sas

1               c:\subfolder1\subprogram1.sas

2               c:\subfolder1\subfolder2\subsubprogram1.sas

1               c:\subfolder1\subprogram2.sas

...

Ask a Question
Discussion stats
  • 2 replies
  • 240 views
  • 0 likes
  • 2 in conversation