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

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

1 ACCEPTED SOLUTION

Accepted Solutions
overmar
Obsidian | Level 7

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

4 REPLIES 4
overmar
Obsidian | Level 7

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;

rakeshvvv
Quartz | Level 8

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

Best regards

Rocky

art297
Opal | Level 21

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;

rakeshvvv
Quartz | Level 8

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.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 2439 views
  • 4 likes
  • 3 in conversation