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
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;
did you miss the set statement?
data want;
set have end = last;
if not last then output;
run;
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;
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
Thank you @art297 . Just out of curiosity, do you still see much traffic on SAS-L?
@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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.