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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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