BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Florent
Quartz | Level 8

Hi all,

 

I am looking for a way to dynamically retrieve the name/path of the SAS programs that are being executed (i.e. the information would remain correct if a program would be moved to a different folder and/or would be renamed), but with the specificity that the different programs are called in a sequence making use of %INCLUDE statements.

I have found many macros doing that perfectly for the main program (i.e. the one in which the %INCLUDE statements are coded), but it does not work for the programs which are included (returned path and program names remain the names of the main program).

I guess this is due to the fact that the %include statement only append the code of a SAS program into the program making the calling?

I am working on SAS 9.4 on Windows 10.

Would there be anyone who already had this need and found a solution? Here below, a representation of what I would like to get:

 

Main program: C:\Users\&sysuserid.\Desktop\Program1.sas
                             path value = C:\Users\&sysuserid.\Desktop
                             program name = Program1.sas

 First include statement:  %include "C:\Users\&sysuserid.\Desktop\Program2.sas";
                             path value = C:\Users\&sysuserid.\Desktop
                             program name = Program2.sas

Second include statement:  %include "D:\Program3.sas";
                             path value = D:\
                             program name = Program3.sas

Many thanks in advance for your help.

Kr,

Florent

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

SAS now sets that information into macro variables.

 

%let path=%sysfunc(pathname(work));
data _null_;
  file "&path/test.sas" ;
  put '%put &=SYSINCLUDEFILEDEVICE;'
    / '%put &=SYSINCLUDEFILEDIR;'
    / '%put &=SYSINCLUDEFILEFILEREF;'
    / '%put &=SYSINCLUDEFILENAME;'
  ;
run;

%include "&path/test.sas" ;

filename test "&path/test.sas";
%include test ;

Results

390   %include "&path/test.sas" ;
SYSINCLUDEFILEDEVICE=DISK
SYSINCLUDEFILEDIR=C:\...
SYSINCLUDEFILEFILEREF=
SYSINCLUDEFILENAME=test.sas
395
396   filename test "&path/test.sas";
397   %include test ;
SYSINCLUDEFILEDEVICE=DISK
SYSINCLUDEFILEDIR=C:\...
SYSINCLUDEFILEFILEREF=TEST
SYSINCLUDEFILENAME=test.sas

View solution in original post

4 REPLIES 4
ballardw
Super User

It might help to include examples of the macros or code you have attempted that don't work so you don't get those or similar suggestions.

 

What to want for output to this? An entry in a the LOG, a macro variable, write to a data set? Or is this supposed to parse a code file?

 

I would tend to take any of my %include statements and add the appropriate code in the main program. Such as if I wanted something in the LOG:

%put "Calling Program: Program2.SAS in C:\Users\&sysuserid.\Desktop";


%include "C:\Users\&sysuserid.\Desktop\Program2.sas";
Florent
Quartz | Level 8

Hi ballardw,

 

An entry in the LOG was indeed the idea.

 

Unfortunately, I wanted to avoid typing that kind of hard-coded %put statements in the programs because that would remain static (I am looking for a dynamic way to trace programs names and locations (in case a program would be renamed and/or moved to a different location).

 

The reply from Tom gives exactly what I was looking for. I was just not aware that the referred automatic macro-variables were introduced in SAS 9.4 but they are pretty much handy!

 

Kind regards,

Florent

Tom
Super User Tom
Super User

If you just want to see the filename in the LOG you don't have to do anything. SAS already writes a NOTE with that information.

746   %include code /source2 ;
NOTE: %INCLUDE (level 1) file CODE is file C:\...\AppData\Local\Temp\1\SAS Temporary
      Files\_TD8300_..._\#LN00084.
747  +* Temporary file;
NOTE: %INCLUDE (level 1) ending.
Tom
Super User Tom
Super User

SAS now sets that information into macro variables.

 

%let path=%sysfunc(pathname(work));
data _null_;
  file "&path/test.sas" ;
  put '%put &=SYSINCLUDEFILEDEVICE;'
    / '%put &=SYSINCLUDEFILEDIR;'
    / '%put &=SYSINCLUDEFILEFILEREF;'
    / '%put &=SYSINCLUDEFILENAME;'
  ;
run;

%include "&path/test.sas" ;

filename test "&path/test.sas";
%include test ;

Results

390   %include "&path/test.sas" ;
SYSINCLUDEFILEDEVICE=DISK
SYSINCLUDEFILEDIR=C:\...
SYSINCLUDEFILEFILEREF=
SYSINCLUDEFILENAME=test.sas
395
396   filename test "&path/test.sas";
397   %include test ;
SYSINCLUDEFILEDEVICE=DISK
SYSINCLUDEFILEDIR=C:\...
SYSINCLUDEFILEFILEREF=TEST
SYSINCLUDEFILENAME=test.sas

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
  • 4 replies
  • 3230 views
  • 1 like
  • 3 in conversation