Help using Base SAS procedures

Remove less than 10 observations

Reply
Occasional Contributor
Posts: 15

Remove less than 10 observations

Hi

Any one can you help with this? I used to use this code to remove less than 10 observations in the same year and industry and it works. But I need to create a dataset for each year and the run the code.

So, can you help me to modify this code to run it for pooled sample including all the years?

Thanks




the dataset
Firm industry year
x 22 2001
z 33 2002
v 33 2002
b 14 2005
w 22 2001
x 22 2002
x 22 2003


The code

proc sort data=data;
by industry;
run;

proc tabulate data=dataset out= dataset_1;
class industry;
table industry*n;
run;

data dataset_1;
set dataset_1;
drop _table_;
drop _page_;
drop _type_;
run;


proc sort data= dataset;
by industry;
run;

proc sort data= dataset_1;
by industry;
run;

data dataset_2;
merge dataset dataset_1;
by industry;
run;

data dataset_3;
set dataset_2;
if n < 10 then delete;
run;
--------------------------------------------------------------
Super Contributor
Super Contributor
Posts: 365

Re: Remove less than 10 observations

Hello q1234,

This is a possible solution:
[pre]
proc freq data=data noprint;
tables Industry*Year /out=f (where=(count > 10));
run;
proc SQL;
create table r as
select a.*
from data as a, f as b
where a.year=b.year and a.industry=b.industry
;quit;
[/pre]
Sincerely,
SPR
Occasional Contributor
Posts: 15

Re: Remove less than 10 observations

Many thanks
Trusted Advisor
Posts: 1,300

Re: Remove less than 10 observations

> data dataset_3;
> set dataset_2;
> if n < 10 then delete;
> run;



data dataset_3;
set dataset_2;
if _n_ < 10 then delete;
run;
SAS Super FREQ
Posts: 8,743

Re: Remove less than 10 observations

Hi:
An aside comment...if all you want to do is drop variables from the OUT= dataset, then this is OK syntax:
[pre]
proc tabulate data=dataset
out=dataset_1(drop=_table_ _type_ _page_);
class industry;
table industry*n;
run;
[/pre]

cynthia
Ask a Question
Discussion stats
  • 4 replies
  • 631 views
  • 0 likes
  • 4 in conversation