Wednesday, 9 January 2013

NOTE: Executing a PROC from a DATA Step

I stumbled across a most informative SAS Global Forum paper the other day, and I wanted to share it with you! In his Executing a PROC from a DATA Step paper, SAS's Jason Secosky describes the RUN_MACRO and DOSUBL functions, both of which were new to me. RUN_MACRO and DOSUBL enable DATA step code to immediately execute a macro and act on the resulting output data set.

RUN_MACRO was introduced in SAS V9.2, and DOSUBL experimentally in V9.3.

The RUN_MACRO function executes a macro and waits for it to complete. RUN_MACRO can be called only from a user-written function created with the FCMP procedure. As a result, you have to write three blocks of code to execute a PROC from a DATA step: Macro to execute a PROC; User-written function to execute the macro; DATA step to call the user-written function. This can be a chore, but can be worth it in the right circumstances.

DOSUBL executes SAS code directly from a DATA step. Unlike RUN_MACRO, DOSUBL can be called directly from a DATA step without the need for a user-written function.

If you're into advanced SAS coding, you need to know about RUN_MACRO and DOSUBL. They probably don't allow you to do anything you couldn't do without them, but they sure make your code a lot simpler and easier to maintain.

2 comments:

  1. Good tip. This is exciting stuff. For macro programmers, it's worth taking a look at Mike Rhoads' paper on the "Macro Function Sandwich" which, by using RUN_MACRO, allows a function-style macro to execute a DATA step or PROC. Wild stuff. Hopefully SAS will keep refining RUN_MACRO and DOSUBL.

    http://support.sas.com/resources/papers/proceedings12/004-2012.pdf

    ReplyDelete
    Replies
    1. Thanks Quentin. I hadn't come across Mike's paper. I'll mention that in a subsequent post, for sure.

      There's a lot of mileage in what can be achieved within this subject area. Maybe there'll be more papers at this year's SAS Global Forum.

      Delete