DATA Step, Macro, Functions and more

how to extract list of all macros in a program

Accepted Solution Solved
Reply
Regular Contributor
Posts: 161
Accepted Solution

how to extract list of all macros in a program

I have a program which has lot of macro calls and i neeed to make a list of existing macro calls in the program.

How can i do that?

 

any help please


Accepted Solutions
Solution
‎08-23-2016 08:26 AM
Super User
Posts: 5,511

Re: how to extract list of all macros in a program

You would be better off modifying the macros.  Add %PUT statements that write messages about what the macro is going:  beginning execution, creating a data set, ending execution.  That's more reliable, and relatively easy to do.

 

Otherwise, you face many additional complications such as macros that create a data set each time through a loop, macros that call other macros, and extend that idea:  macros that call macros that call macros.

View solution in original post


All Replies
Super User
Posts: 19,817

Re: how to extract list of all macros in a program

You could start by searching the program for all %WORD

 

Then you'll have to filter out all the automatic macros and possibly any use of % in Like comparisons. 

 

Super User
Super User
Posts: 7,970

Re: how to extract list of all macros in a program

So, you are writing spaghetti code with macro calls all over, and you have no idea of what is in the program - that to me seems to the problem.  Software development in any language is all about the planning and the documentation, design your process, define the inputs/outputs, document the features, create a testing plan.  Then the final 1% of the whole project is writing some code.

 

The alternative, and teh way your going is trying to work out what has happened after the event, which is bound to fail.  Even if you do pull out all the macro calls - and dont forget you would need the paramters to each of those calls and the context of those macro variables - you would need to know the location of the macro file for those (make sure its the correct version), plus resolve conditional logic within those to understand what parts of the macro were used etc.  It can be done, but its a lot of work and is most likely to fail in one way or another.

 

A final note, there is the proc scaproc procedure which is a code analyser:

http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a003199745.htm

This encompasses your code and produces ouput for inputs/outputs/macros - it may help reduce the amount of work you have to do, however a good and robust SDLC process would more or less eliminate the need for this at all.

Regular Contributor
Posts: 161

Re: how to extract list of all macros in a program

Thanks. Basically its a program which creates multiple datasets by macro calls. I can manually pick up the macro calls and make a list but looking for sas code which can pick calls in the program which starts with "%" and list them in a list file

Super User
Super User
Posts: 7,970

Re: how to extract list of all macros in a program

Well, I can't see the process your doing so can't really say much, however why is the code creating many datasets, which you don't know what they are?  Would it not be better to have one dataset output with a by group separator, or outputs datasets, with a consistent prefix.  Various ways round it.  Again, its all about planning and documentation.  A documented process will show inputs/outputs.

Solution
‎08-23-2016 08:26 AM
Super User
Posts: 5,511

Re: how to extract list of all macros in a program

You would be better off modifying the macros.  Add %PUT statements that write messages about what the macro is going:  beginning execution, creating a data set, ending execution.  That's more reliable, and relatively easy to do.

 

Otherwise, you face many additional complications such as macros that create a data set each time through a loop, macros that call other macros, and extend that idea:  macros that call macros that call macros.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 364 views
  • 2 likes
  • 4 in conversation