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

Hi Team,

 

I need to delete the duplicate IDs with certain conditions from following dataset.

 

Data R;
input Id sal flag;
cards;
1 100 1
1 100 0
2 200 0
2 200 1
3 300 0
4 400 0
4 500 0
;
Run;

 

1. ID should be unique

2. If flag has '1' / '0' on same ID then need to keep the row with '1'

3. If flag has only '0' on ID then need to keep that row

4. If flag has multiple '0' with respect to same ID then need to keep any one or SAL is different then any

 

The output could be : 

1 100 1

2 200 1

3 300 0

4 400 0

 

Looking for kind support.

 

Regards,

Uma Shanker Saini

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Try this:

 

 

proc sql;

create table want as

select *

from r

group by id

having sal=max(sal) and flag=max(flag);

quit;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Data R;

input Id sal flag;

cards;

1 100 1

1 100 0

2 200 0

2 200 1

3 300 0

4 400 0

4 500 0

;

Run;

 

proc sort data=r out=temp;

by id sal descending flag;

run;

 

data want;

set temp;

by id sal;

if first.id and first.sal;

run;

 

 

 

umashankersaini
Quartz | Level 8

Hi Novin,

 

Thanks for your quick help and code works perfectly fine as per requirement.

 

It would be greatful if we can use it via proc sql because i need to implement it into approx 40 million obs and trying for SAS DI.

 

Regards,

Uma Shanker Saini

novinosrin
Tourmaline | Level 20

Try this:

 

 

proc sql;

create table want as

select *

from r

group by id

having sal=max(sal) and flag=max(flag);

quit;

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