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
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: */
> %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;
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