BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello,

 

I have a dataset x with tempID_1 to 3.   I would like to do the following steps:

1. If TempID_3 are duplicates, and TempID_1 are the same IDs, then the comment is the same.

2.  Otherwise, it's not.

 

Data Y is the result I am looking for.  Thanks.

 

data x;
      infile datalines dsd;
  input TempID_1 : $15. TempID_2 : $15.  TempID_3 : $15. ;
datalines;
21156, 8946, 7852,  
21156, 8956, 7852, 
24597, 1596, 4113,
10235, 0546, 4113,
C1156, 4286, 0008, 
200, X1O23, UV689,
208, 8MO23, UV689,
579, HL2489, GJ627,
C1156, 4986, 0008,
21156, 8956, 7852, 
;

data y;
      infile datalines dsd;
  input TempID_1 : $15. TempID_2 : $15.  TempID_3 : $15. Comment : $15.;
datalines;
21156, 8946, 7852, same, 
21156, 8956, 7852, same,
24597, 1596, 4113, Diff,
10235, 0546, 4113, Diff,
C1156, 4286, 0008, same,
200, X1O23, UV689, Diff,
208, 8MO23, UV689, Diff,
579, HL2489,GJ627, same,
C1156, 4986, 0008, same,
21156,  , 7852, same,
;
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

HI @ybz12003  See if this helps

 


data x;
      infile datalines dsd;
  input TempID_1 : $15. TempID_2 : $15.  TempID_3 : $15. ;
datalines;
21156, 8946, 7852,  
21156, 8956, 7852, 
24597, 1596, 4113,
10235, 0546, 4113,
C1156, 4286, 0008, 
200, X1O23, UV689,
208, 8MO23, UV689,
579, HL2489, GJ627,
C1156, 4986, 0008,
21156, 8956, 7852, 
;

proc sql;
create table want(drop=rn) as
select *,ifc(count(distinct tempid_1)=1,'same','Diff') as Comment
from (select *,monotonic() as rn from x)
group by tempid_3
order by rn;
quit;

Kind Regards!

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

HI @ybz12003  See if this helps

 


data x;
      infile datalines dsd;
  input TempID_1 : $15. TempID_2 : $15.  TempID_3 : $15. ;
datalines;
21156, 8946, 7852,  
21156, 8956, 7852, 
24597, 1596, 4113,
10235, 0546, 4113,
C1156, 4286, 0008, 
200, X1O23, UV689,
208, 8MO23, UV689,
579, HL2489, GJ627,
C1156, 4986, 0008,
21156, 8956, 7852, 
;

proc sql;
create table want(drop=rn) as
select *,ifc(count(distinct tempid_1)=1,'same','Diff') as Comment
from (select *,monotonic() as rn from x)
group by tempid_3
order by rn;
quit;

Kind Regards!

ybz12003
Rhodochrosite | Level 12

Thank you!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 977 views
  • 1 like
  • 2 in conversation