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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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