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

hi all,

 

I have a large data set that includes multiple rows for some subjects. Can anyone tell me how to (1) view all of the entries for which this is the case and (2) remove all entries except for the first one for each subject, And ideally place them in a different data set?

 

tia for any help,

 

leslie

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@amigapomba 

Proc Sort should give you an easy option to implement such logic.

data have;
  do subject=3,2,4,1,1,3,2,2;
    otherVar+1;
    output;
  end;
  stop;
run;

proc sort nodupkey
  data=have 
  out=firstSubj  
  dupout=dupSubj 
  ;
  by subject;
run;

title 'firstSubj';
proc print data=firstSubj;
run;
title 'dupSubj';
proc print data=dupSubj;
run;
title;

Capture.JPG

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

For part 2:

 

/* UNTESTED CODE */
proc sql;
    create table want as select * from have 
        group by subject having count(subject)=1;
quit;

 

--
Paige Miller
amigapomba
Fluorite | Level 6

Thank you! I am not sure I need to delete yet so I have not tried your code. does it remove all entries where count>1, including first?

 

thanks again,

 

leslie

PaigeMiller
Diamond | Level 26

You are correct, and so I withdraw my solution.

--
Paige Miller
Patrick
Opal | Level 21

@amigapomba 

Proc Sort should give you an easy option to implement such logic.

data have;
  do subject=3,2,4,1,1,3,2,2;
    otherVar+1;
    output;
  end;
  stop;
run;

proc sort nodupkey
  data=have 
  out=firstSubj  
  dupout=dupSubj 
  ;
  by subject;
run;

title 'firstSubj';
proc print data=firstSubj;
run;
title 'dupSubj';
proc print data=dupSubj;
run;
title;

Capture.JPG

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 872 views
  • 2 likes
  • 3 in conversation