Hi all; Thanks in advance for your answers
My question is
how to choose the rows where eid occurring more than once?
data abc;
input eid name$ age;
cards;
100 ppp 26
100 ppp 26
100 ppp 25
101 qqq 32
102 qqw 31
102 qqq 32
104 yyy 53
102 xxx 51
;
proc sql;
select * from abc group by eid having count(*)>1;
quit;
Thank you
proc sort data=abc;
by eid;
run;
data abc1 eid(keep=eid);
set abc;
by eid;
if first.eid=1 then count=0;
count+1;
if _N_ <> 1 and count>1 then output eid;
run;
proc sort data=eid nodupkey;
by eid;
run;
data abc_op;
merge abc(in=a) eid(in=b);
by eid;
if a=1 and b=1;
run;
Any other simple solutions of doing this in a data step ?
By
Sure.
proc sort data=abc; by eid; run;
data want;
set abc; by eid;
if not (first.eid and last.eid);
run;
proc print data=want noobs; run;
PG
data step version solution.
data abc; input eid name$ age; cards; 100 ppp 26 100 ppp 26 100 ppp 25 101 qqq 32 102 qqw 31 102 qqq 32 104 yyy 53 102 xxx 51 ; run; proc sort data=abc;by eid;run; data want; set abc; by eid; if not (first.eid and last.eid); run;
Xia Keshan
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.