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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.