BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Q1983
Lapis Lazuli | Level 10

data have;

input ln_no $ state $ loans amt;

datalines;

 

1123 AL 1 100

1123 AL 1 100

1123 AL 2 150

1233 AL 2 150

CA 3 50

;

run;

data want;

 

/*if last. then delete;run;*/

end = last;

if not last then output;

run;

I have tried several methods to delete the last row of the datastep.  How would I delete the last observation

1 ACCEPTED SOLUTION

Accepted Solutions
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
data have;
input ln_no : $ state : $ loans amt;
datalines;
1123 AL 1 100
1123 AL 1 100
1123 AL 2 150
1233 AL 2 150
1234 CA 3 50
;
run;
data want;
	set have end=last;
	if not last then output;

run;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

did you miss the set statement?

 

data want;

 set have end = last;

if not last then output;

run;

 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
data have;
input ln_no : $ state : $ loans amt;
datalines;
1123 AL 1 100
1123 AL 1 100
1123 AL 2 150
1233 AL 2 150
1234 CA 3 50
;
run;
data want;
	set have end=last;
	if not last then output;

run;
art297
Opal | Level 21

This question was cross posted on the SAS-L bulletin board. There, @data_null__ showed a method that is way more efficient, namely one that doesn't require reading and re-writing all of the records you want to keep:

data have;
  point=nobs;
  modify have nobs=nobs point=point;
  remove;
  stop;
run;

Art, CEO, AnalystFinder.com

 

novinosrin
Tourmaline | Level 20

Thank you @art297 . Just out of curiosity, do you still see much traffic on SAS-L?

art297
Opal | Level 21

@novinosrin: No, the traffic there has been diminishing for a number of years now. However, I still look there every day as it doesn't require a lot of time and I still learn things that I otherwise would have missed.

 

Art, CEO, AnalystFinder.com

 

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
  • 5 replies
  • 11258 views
  • 1 like
  • 4 in conversation