Date: Mon, 1 Dec 2008 00:40:33 -0800
Reply-To: RolandRB <rolandberry@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: RolandRB <rolandberry@HOTMAIL.COM>
Organization: http://groups.google.com
Subject: Re: if..then in a macro
Content-Type: text/plain; charset=ISO-8859-1
On 1 Dez., 08:52, n <nikhil.abhyan...@gmail.com> wrote:
> hi all;
>
> I have written a macro for plotting a histogram of variables in a
> dataset.
> I have used an if..then statement to ignore the variables which have
> equal lower and upper quartiles.
> However, the if..then statement doesn't appear to have any effect.
> Please go through it and tell me if there are any errors.
> Do I need to provide any more details?
>
> Thanks
>
> The macro goes like...
>
> %macro quartile_trim (variable, q1, q3);
>
> data training_trunc_q; set libname.training;
> if _n_ = 1 then set libname.training_quartiles;
> if &variable >= ( &q3 + 1.5 * (&q3 - &q1)) then delete;
> if &variable <= ( &q3 - 1.5 * (&q3 - &q1)) then delete;
> drop _freq_;
> keep &variable success;
> run;
>
> %if &q3 ne &q1 %then %do;
>
> ods rtf file = "C:\&variable.doc";
> proc univariate data = training_trunc_q noprint;
> class success;
> var &variable;
> histogram &variable;
> run;
> ods rtf close;
> %end;
> %mend;
>
> %quartile_trim (var1, q1_var1, q3_var1);
> %quartile_trim (var2, q1_var2, q3_var2);
> %quartile_trim (var3, q1_var3, q3_var3);
>
> 'q1_var1' and 'q3_var1' are the lower and upper quartiles of the
> variable 'var1' resp.
>
> var1 and var2 have equal, whereas var3 has distinct lower and upper
> quartiles.
> However, SAS is creating an empty rtf file for var1 and var2 too.
The macro %if statement is just comparing the text of the variables
and not comparing their values. If you wanted to compare their values
then you can still do this but it must be in a data step.
|