02-04-2015 05:28 AM
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.
02-04-2015 06:07 AM
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 :
call execute(' data _null_; call symputx("sasexecfilename", "c:\temp\subfolder1\SubProgram1.sas"); run;');
call execute('%include "c:\temp\subfolder1\SubProgram1.sas" ');
In SubProgram1.sas ,specify this kind of macro variable sasexecfilename :
%let sasexecfilename= ;
02-04-2015 06:38 AM
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: