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

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 9592 views
  • 1 like
  • 4 in conversation