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

Hi,

I wan to delete duplicate rows using proc sql (it is possible by proc sort with nodupkey)

For ex -  In the below example, i want to remove duplicates on the basis of name and age.

Input  -

id name  age company

1 aik 26 tcs

2 aik 29 infosys

3 bik 23 wns

4 bik 23 tcs

5 cik 30 infosys

6 cik 28 wns

Output -

id name  age company

1 aik 26 tcs

2 aik 29 infosys

3 bik 23 wns

5 cik 30 infosys

6 cik 28 wns

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input id name $  age company $;
cards;
1 aik 26 tcs
2 aik 29 infosys
3 bik 23 wns
4 bik 23 tcs
5 cik 30 infosys
6 cik 28 wns
;
run;
proc sql;
 select *
  from have
   group by name,age
     having id=min(id);
quit;

Xia Keshan

View solution in original post

4 REPLIES 4
Reeza
Super User

Use Select Distinct to get unique records.

proc sql;

create table want as

select distinct id, name, age, company

from have;

quit;

nikunjgattani
Obsidian | Level 7

Hi Reeza,

Your query will create distinct rows, i am looking for distinct name and age combination only.

Thanks

Nikunj

Reeza
Super User

For duplicates do you care which company gets attached?

You can basically do a group by and summarize on those columns, a data step with first/last gives you more control.

proc sql;

create table want as

select min(id) as ID, name, age, min(company) as company

from have

group by name, age

order by id, name, age;

quit;

Ksharp
Super User
data have;
input id name $  age company $;
cards;
1 aik 26 tcs
2 aik 29 infosys
3 bik 23 wns
4 bik 23 tcs
5 cik 30 infosys
6 cik 28 wns
;
run;
proc sql;
 select *
  from have
   group by name,age
     having id=min(id);
quit;

Xia Keshan

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 24640 views
  • 5 likes
  • 3 in conversation