sasenterprise-guiderowdeleting

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


Solution

  • 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;