BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Wow! What a long subject line! But I think it actually captures exactly what I am trying to do. I am a beginner, so please bear with me.

I have a dataset where one of the variables is 'SupervisorName'. What I would like to be able to do is count the number of times that a particular supervisor name occurs and delete all records which contain a supervisor name that doesn't appear more than 4 times in the dataset.

Example Dataset (this data has already been read into a SAS dataset):

Jim 3 4
Jim 4 5
Jim 6 7
Jim 6 8
Jim 3 2
Suzy 3 1
Suzy 2 1

Given this data, I want to delete all records which have Suzy as the supervisor since she occurs less than 4 times. Leaving only observations where Jim is the supervisor. This is just example data, the dataset I will be performing this on has hundreds of observations.

Thanks you so much for the help!
-jeff
2 REPLIES 2
Bill
Quartz | Level 8
Here's one way ...

data Test;
input Name $1-4 Number Value;
datalines;
Jim 3 4
Jim 4 5
Jim 6 7
Jim 6 8
Jim 3 2
Suzy 3 1
Suzy 2 1
;
run;

proc freq data=Test;
table Name/out=SuprvCnt;
run;

proc sort data=test;
by name;
run;


data Test2;
merge Test (in=a)
SuprvCnt (in=b where=(Count >4));
by Name;
if b;
run;
ChrisNZ
Tourmaline | Level 20
This is compact and easy to read. What out for 2-pass sql performance on large volumes.
[pre]
data t;
input name $ a b;
cards;
Jim 3 4
Jim 4 5
Jim 6 7
Jim 6 8
Jim 3 2
Suzy 3 1
Suzy 2 1
run;
[/pre][pre]
proc sql;
create table t1(drop=c) as
select *, count(name) as c
from t
group by name
having c >4 ;
quit;
[/pre]

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 2021 views
  • 0 likes
  • 3 in conversation