BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

Hello:

 

I would like to find out the same ID from two variables ID1 and ID2.  Then, I created new variable "Same" to see if there is, and flag it with number 1, and count the total number of the same ID.  However, the new "same" column is '.'  which it is not the result I would like to.  I would like to match result shown as the attachment.  What is the problem?

 

data test1;
input ID HR Score;
cards;
1 89 60
2 69 61
3 49 62
4 85 63
5 56 64
6 75 65
7 90 66
;
run;

data test2;
input ID TR Score;
cards;
2 60 50
4 61 40
6 62 60
8 63 65
9 64 78
10 65 79
11 66 90
;
run;

 

data testID1;
set test1 (keep=ID);
by ID;
run;

 

data testID2;
set test2 (keep=ID);
by ID;
run;

 

data test12;

merge testID1(in=intestID1 rename=(ID=ID1))

testID2(in=intestID2 rename=(ID=ID2));

run;

data test13;

set test12;

if ID1 = ID2 then

same = 1;

by ID2;

run;

 

4 REPLIES 4
Reeza
Super User

There's no BY statement in your MERGE.

ybz12003
Rhodochrosite | Level 12

Also, how to count the total number of the same ID.  Please see the attachment.  

Reeza
Super User

Is your original question answered?

If so, mark this question as solved and please ask a new one. 

I won't open attachments so post everything directly into the forum.

ybz12003
Rhodochrosite | Level 12

Hi, Reeza: I have added by on the merged dataset.  It doesn't work.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1419 views
  • 0 likes
  • 2 in conversation