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

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

;

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

proc sql;

select * from abc group by eid having count(*)>1;

quit;

PG

View solution in original post

5 REPLIES 5
PGStats
Opal | Level 21

proc sql;

select * from abc group by eid having count(*)>1;

quit;

PG
manjo
Calcite | Level 5

Thank you

PGStats
WWW_BIGINFOANALYSIS_COM
Calcite | Level 5

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

http://www.biginfoanalysis.com

PGStats
Opal | Level 21

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

PG
Ksharp
Super User

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: 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
  • 5 replies
  • 882 views
  • 8 likes
  • 4 in conversation