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 would like to list the duplicate observations in 'Found' column.  Please advice how.  Thanks.

 

Best,

 

data Founddup;

informat name $80.;

input name $ found;

cards;

If_True 1

If_True_kary 1

If_True_kary 1

If_True_John 3

If_Not 24

If_Not 24

If_Not_Carol 24

If_Not_Carol 24

If_Not_Carol 24

If_False_Joe 288

If_False_Joe 288

;

 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21
data want;
  set Founddup;
  by found notsorted;
  if not(first.found and last.found);
run;
proc print data=want;
run;

Art, CEO, AnalystFinder.com

 

View solution in original post

7 REPLIES 7
art297
Opal | Level 21
data want;
  set Founddup;
  by found notsorted;
  if not(first.found and last.found);
run;
proc print data=want;
run;

Art, CEO, AnalystFinder.com

 

ybz12003
Rhodochrosite | Level 12

Just curious, is there a way that sort the 'found' duplicate obs after the 'not (first and last)' statement? Thanks.

art297
Opal | Level 21

Not sure what you're asking. My suggestion was based on the existing order of the records. If you needed it sorted, I'd go with the proc sort nouniquerec option that @Reeza suggested. 

 

Art, CEO, AnalystFinder.com

 

ybz12003
Rhodochrosite | Level 12

Well, the proc sort code doesn't work in my actual dataset.. Yours works.   Basely, I would like to sort the dupicate numbers from zero to largest.  I found your code doesn't come with this function.  I need to add proc sort on more step.  I wish I could do it in one data steps.

 

data want;

set Founddup;

by found notsorted;

if not(first.found and last.found);

run;

 

proc sort data=want; by found; run;

Reeza
Super User

@ybz12003 wrote:

Well, the proc sort code doesn't work in my actual dataset..


It's not clear who you're responding to, please quote the original post in your response.

 

PROC SORT will work for your situation in a single step. If it doesn't you're doing something wrong.

art297
Opal | Level 21

Couldn't you just use?:

proc sort data=have out=duplicates  nouniquerec;
  by found name;
run;

Art, CEO, AnalystFinder.com

 

Reeza
Super User

NOUNIQUEREC option in PROC SORT does exactly this. You can also use the NOUNIQUEKEY if you're looking at specific variables to identify duplicates.

 

/*This code demonstrates how to keep only duplicate observations in a data set*/

%*Create sample data set;
data have;
informat name $80.;
input name $ found;
cards;
If_True 1
If_True_kary 1
If_True_kary 1
If_True_John 3
If_Not 24
If_Not 24
If_Not_Carol 24
If_Not_Carol 24
If_Not_Carol 24
If_False_Joe 288
If_False_Joe 288
;
run;

%*Sort with NOUNIQUEREC option;
proc sort data=have out=duplicates  nouniquerec;
by name found;
run;

https://gist.githubusercontent.com/statgeek/1ff5a4aaca9b3f875d4defdaa598ae5e/raw/87a7485a46add02b5f0...

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 7 replies
  • 1019 views
  • 2 likes
  • 3 in conversation