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-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!

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.

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
  • 22985 views
  • 5 likes
  • 3 in conversation