turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Dupout Option in PROC SQL

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2014 09:42 AM

Hi,

I have a table and I would like to dup out the duplicates using the PROC SQL... Can anyone help on this regard,

The query should be exactly a replica of the below query in sas. I would need "Z" dataset in PROC SQL.

proc sort data=X out=Y nodupkey dupout=Z;

by A B C;

run;

Thanks

Rocky

Accepted Solutions

Solution

01-13-2014
11:03 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2014 11:03 AM

This paper explains how to do it and the comparisons of the different SAS techniques to identify duplicates and on pg 5/6 identifies how to mimic dupout in proc sql. The thing is that you will not get as clean of an output because you will also get the copy of the non-duplicated observation rather than just the observations which were removed. http://www.nesug.org/proceedings/nesug06/cc/cc24.pdf

data x;

input a b c;

datalines;

1 1 1

1 1 1

1 1 1

1 2 1

1 2 1

2 2 2

1 2 2

;

run;

proc sql;

create table y as

select distinct a, b, c

from x;

create table counts as

select a, b, c, count(*) as IDCount

from x

group by a, b, c;

select IDCount, count(*) as N

from counts

group by IDCount;

create table z as

select T.*

from x T, counts C

where T.a = C.a and t.b=c.b and t.c=c.c and C.IDCount > 1 ;

quit;

All Replies

Solution

01-13-2014
11:03 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2014 11:03 AM

This paper explains how to do it and the comparisons of the different SAS techniques to identify duplicates and on pg 5/6 identifies how to mimic dupout in proc sql. The thing is that you will not get as clean of an output because you will also get the copy of the non-duplicated observation rather than just the observations which were removed. http://www.nesug.org/proceedings/nesug06/cc/cc24.pdf

data x;

input a b c;

datalines;

1 1 1

1 1 1

1 1 1

1 2 1

1 2 1

2 2 2

1 2 2

;

run;

proc sql;

create table y as

select distinct a, b, c

from x;

create table counts as

select a, b, c, count(*) as IDCount

from x

group by a, b, c;

select IDCount, count(*) as N

from counts

group by IDCount;

create table z as

select T.*

from x T, counts C

where T.a = C.a and t.b=c.b and t.c=c.c and C.IDCount > 1 ;

quit;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2014 11:53 AM

Thanks...I got the exact result I was looking for. Thanks for your assistance.

Best regards

Rocky

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2014 11:11 AM

The only way to insure the same result would be to first run a data step where you would add a rank within the order fields.

There is an undocumented function in proc sql, monotonic, that can be used to produce the same result but, as it isn't documented, there is always the chance that one of the times you run it you won't get the intended result.

However, that said, try the following:

proc sql;

create table y (drop=rank) as

select *,monotonic() as rank

from x

group by a,b,c

having rank eq min(rank)

order by a,b,c

;

create table z (drop=rank) as

select *,monotonic() as rank

from x

group by a,b,c

having rank ne min(rank)

order by a,b,c

;

quit;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2014 11:59 AM

Thanks Arthur.....It gave the intended results but I wasn't sure about the functionality of Monotonic....So I am using the other approach. Thanks for your time and assistance.