Date: Wed, 1 Apr 2009 11:14:17 -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: proc sql and catx question
On Wed, 1 Apr 2009 10:26:55 -0400, D T <sasandstats@LIVE.COM> wrote:
...
>if my q19 value in table a is the same as one of the values
>in my variable descr in table b, use the value stored in table b in the
>variable vname to set the variable with the same name in table a to 1, and
set a variable called flag19 to 1.
...
hi, D T,
here is one way using a data step. hth.
cheers,
chang
/* test data */
data one;
input q19 $ q19a q19b flag19;
cards;
x 0 0 0
y 0 0 0
z 0 0 0
;
run;
data two;
input descr $ vname $;
cards;
v q19a
w q19a
y q19b
;
run;
/* (1) lookup q19 value, say y, in descr;
(2) if found, then read vname value, here q19b;
(3) find the variable in a and set it, q19b to 1,
for the second obs, and also set flag19. */
data three;
if _n_ = 1 then do;
if 0 then set two; /* to prep pdv */
drop descr vname;
declare hash lookup(dataset:'two');
lookup.definekey('descr');
lookup.definedata('vname');
lookup.definedone();
end;
set one;
descr = q19;
if (0 < lookup.find()) then return;
select(vname);
when("q19a") q19a = 1;
when("q19b") q19b = 1;
otherwise do;
put "error: unknown vname.";
abort;
end;
end;
flag19 = 1;
run;
/* check */
proc print data=three noobs;
run;
/* on lst
q19 q19a q19b flag19
x 0 0 0
y 0 1 1
z 0 0 0
*/