LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2008, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 4 Jul 2008 14:14:32 -0500
Reply-To:     paul@WUBIOS.WUSTL.EDU
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Paul Thompson <paul@WUBIOS.WUSTL.EDU>
Subject:      Macro behavior in IML and DATA step
Content-Type: text/plain; charset=ISO-8859-1; DelSp="Yes"; format="flowed"

The macro system behaves a little differently in IML than it does in other parts of SAS. In IML, each statement is executed immediately, rather than waiting until all code is assembled. This is a bit odd for those who use macros outside of IML.

Here is a simple example. First, we see the normal behavior in the datastep, where the call symput does not affect the value of _i until after the run:

75 options mprint; 76 77 %let _i=1; 78 data _null_; 79 call symput("_i",'2'); 80 put "&_i"; 81 run;

1 NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds

82 %put _i[&_i]; _i[2]

This is all quite what SAS users expect.

In IML, things behave a little differently. Here is a comparable example, with the output brought in from the OUTPUT window shown below.

83 84 %let _i=1; 85 proc iml; NOTE: IML Ready 86 call symput("_i",'2'); 87 print "Current value of _i: &_i"; 88 quit; NOTE: Exiting IML. NOTE: PROCEDURE IML used (Total process time): real time 0.03 seconds cpu time 0.01 seconds

89 %put _i[&_i]; _i[2]

From the OUTPUT window: The SAS System 13:58 Friday, July 4, 2008 6

Current value of _i: 2

I encourage those who have not tried this to do so.

IML is an interesting part of SAS. Its immediate execution component is very useful. It gives the ability of macro code to more tightly self-modify.

This issue was raised by a post or two earlier today. I thought it interesting, so present this small tutorial.


Back to: Top of message | Previous page | Main SAS-L page