BookmarkSubscribeRSS Feed
Hani18
Calcite | Level 5

hello, i'm having troulbe get the table merge with the two different scores which looks like this:

Hani18_0-1634664376006.png

this is my code:

data exercise4;
 input ID $ KneeNumber PreOp OneDay OneWeek OneMonth;
cards;
01 1 0  5  7  10
02 1 0 10 15  15
02 2 3  5  8  10
03 1 0  3  3   3
03 2 0  6  9   9
04 1 0  4 10  10
;
data A (keep=id visit score);
 set exercise4;
 array x{4} PreOp OneDay OneWeek OneMonth;
   do i=1 to 4;
   visit = i;
   score = x{i};
   if kneenumber = 1;
     output;
     end;
run;
data B (keep=id visit score);
 set exercise4;
 array x{4} PreOp OneDay OneWeek OneMonth;
   do i=1 to 4;
   visit = i;
   score = x{i};
   if kneenumber = 2;
     output;
     end;
run;

data merged;
merge A B;
by id;
run;

proc print data=merged;
run;

and this is my output:

Hani18_1-1634664434568.png

 

2 REPLIES 2
tarheel13
Rhodochrosite | Level 12

is the first screenshot your desired output? You have score named the same in both datasets. you should use the rename statement and rename them to score_knee1 and score_knee2 if that is what you want. 

Hani18
Calcite | Level 5
Yes that works. Thank you