DATA Step, Macro, Functions and more

Flag same number from two variables?

Reply
Super Contributor
Posts: 319

Flag same number from two variables?

[ Edited ]

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;

 

Super User
Posts: 19,814

Re: Flag same number from two variables?

There's no BY statement in your MERGE.

Super Contributor
Posts: 319

Re: Flag same number from two variables?

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

Super User
Posts: 19,814

Re: Flag same number from two variables?

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.

Super Contributor
Posts: 319

Re: Flag same number from two variables?

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

Ask a Question
Discussion stats
  • 4 replies
  • 146 views
  • 0 likes
  • 2 in conversation