BookmarkSubscribeRSS Feed
vThanu
Calcite | Level 5

Data ds;

input first $ last $ age;

datalines;

sam sunder 20

sunder sam 20

raj gopal 22

rama rao 21

gopal raj 22

;

run;

 

In the above code 1st observation and 2nd observation are duplicate (first & last are interchanged) & same for 3rd & 5th obs.

I want to eliminate this type of duplicate records.

please can any one help me out (on SAS BASE SAS programm). 

4 REPLIES 4
vThanu
Calcite | Level 5
plz can any one help me out
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You could do:

Data ds;
  input first $ last $ age;
datalines;
sam sunder 20
sunder sam 20
raj gopal 22
rama rao 21
gopal raj 22
;
run;

data want;
  set ds;
  call sortc(first,last);
run;

proc sort data=want nodupkey;
  by first last;
run;
vThanu
Calcite | Level 5

great... thank you ...

kiranv_
Rhodochrosite | Level 12

@RW9 code is nice and clean. another way to do using SQL and this will make sure, which record to pick in this case earlier records are picked.

 

 

Data ds;
  input first $ last $ age;
datalines;
sam sunder 20
sunder sam 20
raj gopal 22
rama rao 21
gopal raj 22
;
run;

data ds1;
set ds;
var = _n_;
run;


proc sql;
create table want(drop=var) as 
select * from ds1
except
select a.* from ds1 a
inner join 
ds1 b
on a.first = b.last
and a.last = b.first
and a.age = b.age
and a.var gt b.var;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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