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 2006, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 24 Jul 2006 11:54:45 -0500
Reply-To:     Kevin Myers <KMyers@PROCOMINC.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Kevin Myers <KMyers@PROCOMINC.NET>
Subject:      Re: SCL Questions (hijacked thread)
Comments: cc: joewhitehurst@bellsouth.net, "Dunn, Toby"
          <Toby.Dunn@TEA.STATE.TX.US>, Doug Rohde <drohde01@COMCAST.NET>
Content-Type: text/plain; charset="iso-8859-1"

Neither Doug nor Toby were quite on target with regard to what I meant by the creation of macro pseudo-functions for use in data step code. The kind of macro that I was talking about is directly usable anywhere in an expression exactly as if it was a true SAS function. Here is a macro pseudo-function and usage example which produces results somewhat similar to those provided by Doug and Toby.

%macro zdiv(num,den);

(ifn((&den)=0,ifn((&num)=0,.,sign(&num)*constant("BIG")),0)+ifn((&den)=0,0,& num)/ifn((&den)=0,1,&den))

%mend zdiv;

data _null_;

do d=.-1,0,1;

do n=.,-1,0,1;

q=%zdiv(n,d); put n= d= q=;

end;

end;

run;

(apologies for the lack of indentation produced by pasting code from the SAS editor into Outlook Express)

Note the use of parentheses to force evaluation of the numerator, denominator, and entire "function" so that this macro can be substituted anywhere a normal SAS function might be used, even if the numerator and/or denominator are expressions themselves or if this function is used as part of a larger expression.

This particular macro "function" is fairly short, but using it can still save a lot of typing if you do a lot of division that needs to be protected from division by zero. More importantly, it also helps clarify coding by making it more obvious what you are trying to do in the main data step code by simplifying the source code expressions in which it is used. I also have a number of other macro functions in my library that compute significantly more complex expressions...

Are there other ways to accomplish the same thing? Yes, many. But I find the above approach to be simpler and more convenient to use in many cases.

To do the same thing from SCL, you would have to embed the associated data step code within an SCL module, compile it, then run the SCL program. It is much simpler to just refer to a macro definition for an often-used complex numeric expression.

s/KAM

----- Original Message ----- From: "Doug Rohde" <drohde01@COMCAST.NET> To: <SAS-L@LISTSERV.UGA.EDU> Sent: Monday, July 24, 2006 9:24 AM Subject: Re: SCL Questions (hijacked thread)

> I don't know if this is what Kevin had in mind, but this is the sort of > pseudo-function I use for protected division (or log, or sqrt, etc.): > > %macro pdiv(newvar,num,denom,default = 0); > if &denom = 0 then &newvar = &default; > else &newvar = &num / &denom; > %mend; > > Then of course I just call it like this: > > data foo; set foo; > %pdiv(foo,var1,var2); > run; > > I am interested to see how something like this is implemented in SCL. > Thanks. > > Doug R > > On Sat, 22 Jul 2006 11:47:40 -0400, Joe Whitehurst > <joewhitehurst@GMAIL.COM> wrote: > > >Kevin, > > > >I have just been trying to douse some of the enthusiasm with which > >some MMMMs have been trying to promote the use of the Antiquated Macro > >Language, and I believe I have had some small success! Some of the > >MMMMs at least now mention SCL sort of as an afterthought when > >suggesting alternative solutions to questions posted by obvious > >neophytes. I understand and often use the Antiquated Macro Language > >to generate SCL code. But, I have not seen a datastep pseudo function > >created by the Antiquated Macro Language that I could not create with > >SCL. Do you have an example handy? > > > >Joe > > > > > > > >> > >> I don't personally agree with Joe's "religious persecution" of macro in > >> favor of SCL. I even know of a few a things that macro can do which SCL > >> cannot do as well (for instance, you can use macros to effectively > create > >> custom data step functions and even generate SCL code


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