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
;
data want; set Founddup; by found notsorted; if not(first.found and last.found); run; proc print data=want; run;
Art, CEO, AnalystFinder.com
data want; set Founddup; by found notsorted; if not(first.found and last.found); run; proc print data=want; run;
Art, CEO, AnalystFinder.com
Just curious, is there a way that sort the 'found' duplicate obs after the 'not (first and last)' statement? Thanks.
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
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;
@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.
Couldn't you just use?:
proc sort data=have out=duplicates nouniquerec; by found name; run;
Art, CEO, AnalystFinder.com
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;
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!
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.