BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
aanan1417
Quartz | Level 8

data have;

input clamnum  sno;

datalines;

900001 1

900001  2

900002  3

900003  4

900003  5

900008  6

;

run;

 

data want;

input clamnum  sno;

datalines;

900002  3

900008  6

;

run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

Not tested:

proc sort data=have out=sorted;
  by clamnum;
run;

data want;
  set sorted;
  by clamnum;

  if first.clamnum and last.clamnum;
run;

Docs: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/n01a08zkzy5igbn173zjz82zsi1s.htm

View solution in original post

3 REPLIES 3
andreas_lds
Jade | Level 19

Not tested:

proc sort data=have out=sorted;
  by clamnum;
run;

data want;
  set sorted;
  by clamnum;

  if first.clamnum and last.clamnum;
run;

Docs: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/n01a08zkzy5igbn173zjz82zsi1s.htm

data_null__
Jade | Level 19

You can create the subset directly from PROC SORT.

 

data have;
   input clamnum  sno;
   datalines;
900001 1
900001  2
900002  3
900003  4
900003  5
900008  6
;
run;

proc sort nounikey data=have out=dups uniout=unique;
   by clamnum;
   run;
proc print data=unique;
   run;
proc print data=dups;
   run;
andreas_lds
Jade | Level 19

Interesting, i have never seen the options "nounikey" ... will have to memorise it.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 476 views
  • 3 likes
  • 3 in conversation