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

Hi 

 

I have a panel data set where each individual has a unique 'RunnerID'. I want to remove all the IDs that have less than 3 observations from my data set

 

Hope you guys can help, thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Do something like this

 

data have;
input RunnerID var;
datalines;
1 1
1 2
1 3
1 4
2 5
2 6
;

proc sql;
   create table want as
   select *
   from have
   group by RunnerID
   having count(RunnerID) ge 3;
quit;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

Please post samples data of what you HAVE and the expected OUTPUT(WANT) for your input. I mean a few records

YoLohse
Fluorite | Level 6

The data I have looks like this, the data lines I want to keep are the yellow ones

 

Capture.PNG

PeterClemmensen
Tourmaline | Level 20

Do something like this

 

data have;
input RunnerID var;
datalines;
1 1
1 2
1 3
1 4
2 5
2 6
;

proc sql;
   create table want as
   select *
   from have
   group by RunnerID
   having count(RunnerID) ge 3;
quit;
YoLohse
Fluorite | Level 6
Thanks man, just what i needed!
ballardw
Super User

Here is an example of one way using SASHELP.CLASS data.

Proc freq data=sashelp.class noprint;
   tables age /out=work.agecount (where=(count>3));
run;

proc sql;
   create table want as
   select b.* 
   from work.agecount as a
        left join
        sashelp.class as b
        on a.age=b.age
   ;
quit;

"RunnerID would take the place of the variable Age in the above code. Obviously your data set would replace SASHELP.CLASS.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1743 views
  • 0 likes
  • 4 in conversation