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 (February 2004, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 6 Feb 2004 10:24:50 -0500
Reply-To:     "Fehd, Ronald J. (PHPPO)" <rjf2@CDC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Fehd, Ronald J. (PHPPO)" <rjf2@CDC.GOV>
Subject:      Re: macro as a function
Comments: cc: knvsol <knvsol@COMCAST.NET>
Content-Type: text/plain; charset="us-ascii"

> From: knvsol [mailto:knvsol@COMCAST.NET] > trying to do the following: > %macro function ( a , b ) ; > %if &b >0 %then

/* this line is being ignored!!* yeah, well, it ought to have a closing slash: */

> &a/&b; > %mend function; > data test ; > input x y ; > result = %function ( x , y ); > cards ; > ; > proc print data=test;run; > > I read a lot of posting about using a macro as a 'function'. > Is there anyway to still acommplish the above code ( check > value b > 0 ) in one single function?

yes, but this isn't the way to do it. if you want to write a data step function you need something like SAS Toolkit.

in your case you need to explicitly write only your SAS code a macro function is not going to do testing of data step variable values

the code that you want is: if Y then Result = X/Y; else Result = .;

you could therefore do the following: %macro Div_If_GE_Zero(Var, Numerator, Denominator); if &Denominator. then &Var = &Numerator. / &Denominator.; else &Var = .;%Mend; usage: %Div_If_GE_Zero(Result,X,Y);

a macro function returns any number of tokens less than a statement in your case there is no macro function solution to the task you have described.

Ron Fehd the macro maven CDC Atlanta GA USA RJF2@cdc.gov

By using your intelligence you can sometimes make your problems twice as complicated. -- Ashleigh Brilliant


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