David Chris
David Chris

Reputation: 255

How to Delete the first 10 and last 10 rows of a SAS Data file?

I am trying to delete the first ten and last ten of a SAS data file But I am not able to do this. By using the code below I am able to delete the last 10 rows but not the first 10.

data b;
set a NOBS=COUNT;

if count <= 10 then delete;
if count -_n_ < 10 then delete;
run;

Can someone please help me on this and provide your suggestions.

Thanks in Advance

Upvotes: 2

Views: 4945

Answers (1)

Sanek Zhitnik
Sanek Zhitnik

Reputation: 726

Use _N_ variable with NOBS statement.

Delete first and last 5 rows in Class table:

data want;
set  sashelp.class  NOBS=COUNT;

if _n_        <= 5 then delete;
if count -_n_ <  5 then delete;
n_ = _n_;
run;

Upvotes: 2

Related Questions