SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Anon123
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

 

if count - _n_ <6;

View solution in original post

3 REPLIES 3
Reeza
Super User

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;
Anon123
Fluorite | Level 6
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.
Reeza
Super User

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

 

if count - _n_ <6;

sas-innovate-white.png

Join us for our biggest event of the year!

Four days of inspiring keynotes, product reveals, hands-on learning opportunities, deep-dive demos, and peer-led breakouts. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 13382 views
  • 0 likes
  • 2 in conversation