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
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;
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;
Thanks...I got the exact result I was looking for. Thanks for your assistance.
Best regards
Rocky
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;
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.
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 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.