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-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 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
  • 1307 views
  • 0 likes
  • 4 in conversation