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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 458 views
  • 1 like
  • 2 in conversation