DATA Step, Macro, Functions and more

call execute or SAS macro

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

call execute or SAS macro

Hello Forum,

I have come across some sas papers that emphasizes the use of call execute rather than SAS macro.  Are there any specific circumstances where call execute is more preferable than  SAS macro.  Thanks for your insights.


Accepted Solutions
Solution
‎12-23-2014 01:10 PM
Super User
Posts: 19,861

Re: call execute or SAS macro

Posted in reply to kaushal2040

No, the point of call execute is to avoid call symput and the creation of extra macro variables.

This may not be the best example but suppose you need to read in multiple text files from DIFFERENT* directories all with the same file structure.

You can use OS commands to generate a list of all the files and store that in a dataset, so you now have a dataset (FILELIST1) that contains all the files you need to read. If you used a macro to loop you'd need to create macro variables for each filename and loop through.

If you used call execute you could feed the filename as a variable to a different macro without having to create the macro variable.

*If the files were in the same directory wildcards allow for a more efficient solution.

View solution in original post


All Replies
Super User
Posts: 19,861

Re: call execute or SAS macro

Posted in reply to kaushal2040

My thoughts, call execute is preferable when your macro is driven by data that is stored in a data set.

Contributor
Posts: 50

Re: call execute or SAS macro

Hi Reeza,

Can you give an example?  Do you mean use of data step interface such as call symput?

Thanks !!!

Solution
‎12-23-2014 01:10 PM
Super User
Posts: 19,861

Re: call execute or SAS macro

Posted in reply to kaushal2040

No, the point of call execute is to avoid call symput and the creation of extra macro variables.

This may not be the best example but suppose you need to read in multiple text files from DIFFERENT* directories all with the same file structure.

You can use OS commands to generate a list of all the files and store that in a dataset, so you now have a dataset (FILELIST1) that contains all the files you need to read. If you used a macro to loop you'd need to create macro variables for each filename and loop through.

If you used call execute you could feed the filename as a variable to a different macro without having to create the macro variable.

*If the files were in the same directory wildcards allow for a more efficient solution.

Respected Advisor
Posts: 3,799

Re: call execute or SAS macro

Posted in reply to kaushal2040

You could save yourself some time by looking at the examples in the online documentation.

Contributor
Posts: 50

Re: call execute or SAS macro

Posted in reply to data_null__

data_null_;

I was also looking at the video of power of call execute.  I still don't think I can use in my case.  So getting insights from SAS gurus

Thanks !!!

Super User
Posts: 19,861

Re: call execute or SAS macro

Posted in reply to kaushal2040

If you have a specific case in mind, you should ask that case. There are always so many alternatives beyond even call execute and macros. In fact, I go out of my way to avoid both in most cases.

🔒 This topic is solved and locked.

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

Discussion stats
  • 6 replies
  • 332 views
  • 6 likes
  • 3 in conversation