turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- How to delete rows?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-24-2016 02:18 PM

How do I delete the last six rows of a dataset?

Accepted Solutions

Solution

07-24-2016
02:38 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-24-2016 02:37 PM

Sorry, it should be COUNT in the IF statement, not NOBS.

if count - _n_ <6;

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-24-2016 02:26 PM

Use NOBS and delete. I'm not sure if it should be less than or less than and equal to in the comparison so both are there.

One will work for you.

```
data want;
set sashelp.class NOBS=COUNT;
if NOBS - _n_ < 6 then delete;
*if NOBS - _n_ <= 6 then delete;
run;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-24-2016 02:36 PM

Thanks however it is not working for me. I get this log:

643

644 data thesis.rank_ndC;

645 set thesis.rank_ndd NOBS=COUNT;

646

647 if NOBS - _n_ < 6 then delete;

648 run;

NOTE: Variable NOBS is uninitialized.

NOTE: Missing values were generated as a result of performing an operation on missing values.

Each place is given by: (Number of times) at (Line)Column).

25 at 647:9

NOTE: There were 25 observations read from the data set THESIS.RANK_NDD.

NOTE: The data set THESIS.RANK_NDC has 0 observations and 11 variables.

643

644 data thesis.rank_ndC;

645 set thesis.rank_ndd NOBS=COUNT;

646

647 if NOBS - _n_ < 6 then delete;

648 run;

NOTE: Variable NOBS is uninitialized.

NOTE: Missing values were generated as a result of performing an operation on missing values.

Each place is given by: (Number of times) at (Line)Column).

25 at 647:9

NOTE: There were 25 observations read from the data set THESIS.RANK_NDD.

NOTE: The data set THESIS.RANK_NDC has 0 observations and 11 variables.

Solution

07-24-2016
02:38 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-24-2016 02:37 PM

Sorry, it should be COUNT in the IF statement, not NOBS.

if count - _n_ <6;