Date: Fri, 13 Apr 2007 13:10:00 -0400
Reply-To: Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject: Re: A SIMPLE MACRO PROBLEM AS A CONTINUATION OF UNCLEANED DATASET
On Fri, 13 Apr 2007 16:49:27 +0000, toby dunn <tobydunn@HOTMAIL.COM> wrote:
>Sasi ,
>
>Uhhh sorry to tell you are wrong.
>
>As a cheesy example (Ian dont get after the design it is only here to
>illistrate that it can be done):
>
>%Macro Chg( Var = ) ;
>%If &Var Eq A %Then %Do ;
> 1
>%End ;
>%Else %If &Var Eq B %Then %Do ;
> 2
>%End ;
>%Else %If &Var Eq C %Then %Do ;
> 3
>%End ;
>%Mend Chg ;
>
>
>Data _Null_ ;
>Do X = 'A' , 'B' , 'C' ;
> Y = Resolve( '%Chg( Var = ' || Put( X , 8. -L ) || ' ) ' ) ;
> Put X= Y= ;
>End ;
>Run ;
Hi,
I think that toby meant something like below. X is a character variable,
which does not need to be put (actually, you can't). On the other hand, the
resolve function returns a character string, which should be input since the
intention seems to be creating a *numeric* variable y. HTH.
Cheers,
Chang
%macro abc2num(var);
%*-- returns 1 for A, 2 for B, 3 for C, otherwise 0 --*;
%*-- note: case sensitive --*;
%*;%index(ABC,%superq(var))
%mend abc2num;
data _null_;
do x = "A", "B", "C", "D";
y = input(resolve(catt('%abc2num(',x,')')), best.);
put x= y=;
end;
run;
/* on log
x=A y=1
x=B y=2
x=C y=3
x=D y=0
*/
|