Date: Fri, 11 Feb 2000 02:28:26 GMT
Reply-To: sashole@mediaone.net
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Subject: Re: Help with macro
Content-Type: text/plain; format=flowed
Victor,
They are not working because they are supposed to assemble DATA step code
executed at the DATA step run-time, not at its compilation time. Your
conditional statements, therefore, should be DATA step, not macro
statements, i.e.
%macro missobs(var, replace);
if &var = . then &var = &replace;
else &var = &var;
%mend missobs;
and alike for the rest. However, there is no need in reassigning a variable
to itself as in &var = &var; it is just an extra work for the computer. So,
the macro becomes
%macro missobs(var, replace);
if &var = . then &var = &replace;
%mend missobs;
However, why bother with macros if all the functionality you need is already
provided by SAS functions and operators. The macro %missobs() can be safely
replaced with
var = max (var, replace*(var eq .));
As for the remaining two pieces, it is even easier. Capping and flooring are
taken care of, respectively, by
var = var min maxi;
and
var = var max mini;
Kind regards,
=====================
Paul M. Dorfman
Jacksonville, FL
=====================
>From: Victor Aina <aina@SFU.CA>
>Reply-To: Victor Aina <aina@SFU.CA>
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Help with macro
>Date: Fri, 11 Feb 2000 00:10:48 GMT
>
>Hello everyone;
>
>I've got a smal piece of code (macro below)
>to replace missing values and take care
>of "outliers". However, the macros are
>not working properly. I have not been
>able to figure oyut why. Any pointers
>and helps appreciated.
>
>Thanks,
>
>Victor.
>
>===========================================================
>
>data temp;
> input x1 x2 x3;
> datalines;
>
>1 4 4
>3 1 .
>1 . 8
>. 1 .
>5 . 3
>7 7 1
>;
>run;
>
>%macro missobs(var, replace);
> %if &var = . %then &var = &replace;
> %else &var = &var;
>%mend missobs;
>
>%macro cap(var, maxi);
> %if &var >= &maxi %then &var = &maxi;
> %else &var = &var;
>%mend missobs;
>
>%macro floor(var, mini);
> %if &var <= &mini %then &var = &mini;
> %else &var = &var;
>%mend missobs;
>
>
>data temp2;
> set temp;
> %missobs(x3, 777);
> %cap(x1, -999);
> %floor(x2, 111);
>run;
>
>proc print data=temp2;
>run;
>
>endsas;
>
>
>--
>
>
>+----------------------------------------------------------+
>| victor aina | e-mail: aina@sfu.ca | fax:(604) 291-5944 |
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
|