Help using Base SAS procedures

Dupout Option in PROC SQL

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 145
Accepted Solution

Dupout Option in PROC SQL

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
Frequent Contributor
Posts: 83

Re: Dupout Option in PROC SQL

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;

View solution in original post


All Replies
Solution
‎01-13-2014 11:03 AM
Frequent Contributor
Posts: 83

Re: Dupout Option in PROC SQL

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;

Frequent Contributor
Posts: 145

Re: Dupout Option in PROC SQL

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

Best regards

Rocky

PROC Star
Posts: 7,363

Re: Dupout Option in PROC SQL

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;

Frequent Contributor
Posts: 145

Re: Dupout Option in PROC SQL

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 777 views
  • 4 likes
  • 3 in conversation