t*******s 发帖数: 289 | 1 table 1
ID HCC1 HCC2 HCC3
a 0 1 1
b 1 1 1
c 1 1 0
d 1 0 0
e 0 0 0
f 0 0 0
g 1 1 0
h 1 1 0
i 1 1 1
j 0 1 1
k 0 0 1
l 0 0 0
m 1 0 0
n 1 0 0
o 1 0 0
p 0 0 1
q 0 1 1
r 0 1 1
s 0 1 0
t 0 0 0
table 2
ID HCC1 HCC2 HCC3
a 1 0 1
b 1 0 1
c 1 0 1
d 0 0 1
e 0 0 0
f 0 0 0
g 0 0 1
h 0 0 1
i 0 0 0
j 0 1 0
k 1 0 0
l 1 0 0
m 1 1 0
n 0 1 1
o 0 1 1
p 0 1 0
q 1 1 0
r 1 1 0
s 1 1 1
t 1 0 0
output table
ID HCC
a HCC2
b HCC3
c HCC4
d HCC1
g HCC1
h HCC1
i HCC1
g HCC2
h HCC2
i HCC2
i HCC3
n HCC1
o HCC1
p HCC3
q HCC3
r HCC3
logic:
join table 1 and 2 on id and HCCi; selecl id and HCCi where HCCi in table 1
is 1 and HCCi in table 2 is 0 |
l****u 发帖数: 529 | 2 I did not check.
data t3;
merge t1 t2(rename=(hcc1=hcc4 hcc2=hcc5 hcc3=hcc6));
by id;
array new1 [3] hcc1 hcc2 hcc3;
array new2 [3] hcc4 hcc5 hcc6;
do i=1 to 3;
if new1[i]-new2[i]=1 then hcc=vname(new1[i]);
end;
run; |
t*******s 发帖数: 289 | 3 Thanks much. Totally there are 254 HCC. Do you mind revising your codes for
references?
【在 l****u 的大作中提到】 : I did not check. : data t3; : merge t1 t2(rename=(hcc1=hcc4 hcc2=hcc5 hcc3=hcc6)); : by id; : array new1 [3] hcc1 hcc2 hcc3; : array new2 [3] hcc4 hcc5 hcc6; : do i=1 to 3; : if new1[i]-new2[i]=1 then hcc=vname(new1[i]); : end; : run;
|
l****u 发帖数: 529 | 4 In 254 hccis, only one gets 1 in t1 and 0 in t2? In case there are more
HCCis per ID that meet your requirement, I modified the code to get more
observations for each id.
I did not check the code. The logic should be correct.
%macro t;
data t3
merge t1 t2(rename=(%do i=1 %to 254;
hcc&i.=c&i.
%end;));
by id;
array new1 [254] hcc1-hcc254;
array new2 [254] c1-c254;
do i=1 to 254;
if new1[i]-new2[i]=1 then do;
hcc=vname(new1[i]);
output;
end;
end;
run;
%mend;
%t |
t*******s 发帖数: 289 | 5 there can be more than one HCC that meets the criteria for each ID, if that
is what you ask. Thanks a lot for your responses and very smart input
【在 l****u 的大作中提到】 : In 254 hccis, only one gets 1 in t1 and 0 in t2? In case there are more : HCCis per ID that meet your requirement, I modified the code to get more : observations for each id. : I did not check the code. The logic should be correct. : %macro t; : data t3 : merge t1 t2(rename=(%do i=1 %to 254; : hcc&i.=c&i. : %end;)); : by id;
|