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-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!

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