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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 352 views
  • 0 likes
  • 2 in conversation