DATA Step, Macro, Functions and more

Delete the last observation in a data Step

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Delete the last observation in a data Step

Hi All,

I am using the infile statement to import text files and I am trying to import everything EXCEPT the last row (as it is the Grand Totals). The last row is dynamic, it could be row 14 or row 20. Is there a way to import N-1 rows?

Thank you

 

 

data Work.Test ;
infile &DataFile dlm=',' firstobs=3 dsd;
length Time_Period $30;
input
Time_Period
ID
Customers

;

run;


Accepted Solutions
Solution
‎05-30-2016 02:44 PM
Respected Advisor
Posts: 4,651

Re: Delete the last observation in a data Step

I would try:

 

infile &DataFile dlm=',' firstobs=3 dsd obs=nobs;

if _n_ = nobs then stop;

PG

View solution in original post


All Replies
Solution
‎05-30-2016 02:44 PM
Respected Advisor
Posts: 4,651

Re: Delete the last observation in a data Step

I would try:

 

infile &DataFile dlm=',' firstobs=3 dsd obs=nobs;

if _n_ = nobs then stop;

PG
Super User
Posts: 9,682

Re: Delete the last observation in a data Step

data x;
 infile '/folders/myfolders/want.txt' end=last length=len;
 input x $varying200. len;
 if not last then output;
run;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 1215 views
  • 2 likes
  • 3 in conversation