BookmarkSubscribeRSS Feed
Anupama29
Calcite | Level 5

Can we have a sas code to get the list of files that sas code is referring to while executing. For Eg: the macros it is referring or the files that has been included in the sas code through out the flow.

1 REPLY 1
SASJedi
SAS Super FREQ

Here's a starting point for you. This data step reads a SAS dataset file, finds macro calls and %INCLUDE statements, and creates a dataset that includes the program name and the macros calls. 

%let myProgram=C:\temp\test.txt;
data calls;
   infile "%superq(myProgram)" end=lastrec;
   length Program $256 MacroName $32;
   retain rxID;
   retain Program "%qscan(%superq(myProgram),-1,\/)";
   drop rxID count;
   if _n_=1 then do;
      rxID=prxparse('/(%(?!(macro|mend))\s*\w*)/i');
   end;
   input;
   if prxmatch(rxID,_infile_) then do;
      MacroName=prxposn(rxID,1,_infile_);
      output;
      count+1;
   end;
   if lastrec and count=0 then do;
      put 'NOTE- ************************************************';
      put 'NOTE: No macro calls or %INCLUDEs in program ' program ;
      put 'NOTE- ************************************************' ;
   end;
run;
proc sql;
select distinct program, macroName 
   from calls
;
quit;

Here are a couple of test "programs" to play with. Save them as test.sas and test2.sas

/* test.sas */
%macro include;
%mend myMacro;
%myMacro
%include "c:\temp";
%include fileref;
print "This is a %test";
/*test2.sas */
macro include;
mend myMacro;
myMacrol
include "c:\temp";
include fileref;
print "This is a test";

When executed against test.sas, this is the result:

Program MacroName
test.sas %include
test.sas %myMacro
test.sas %test

May the SAS be with you!

Mark

Check out my Jedi SAS Tricks for SAS Users

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 500 views
  • 0 likes
  • 2 in conversation