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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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