DATA Step, Macro, Functions and more

Excluding last row when importing a file

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

Excluding last row when importing a file

Hi all,

Hopefully a simple question - what's the best way to exclude the last row of a raw file from being imported into SAS?

I know I can simply take the number of observations minus 1 after importing the data, but would rather condense into one data step if possible.

Thanks!


Accepted Solutions
Solution
‎12-21-2011 06:40 PM
Super User
Super User
Posts: 6,500

Excluding last row when importing a file

data want ;

   infile 'myfile' end=eof ;

   input @ ;

   if eof then delete ;

  input .... ;

run;

View solution in original post


All Replies
Solution
‎12-21-2011 06:40 PM
Super User
Super User
Posts: 6,500

Excluding last row when importing a file

data want ;

   infile 'myfile' end=eof ;

   input @ ;

   if eof then delete ;

  input .... ;

run;

Occasional Contributor
Posts: 16

Excluding last row when importing a file

Thanks Tom!

Valued Guide
Posts: 765

Re: Excluding last row when importing a file

hi ... another idea ...

data new;

infile 'z:\test.txt' end=last;

input a b c;

if ^last;

run;

Super User
Super User
Posts: 6,500

Re: Excluding last row when importing a file

Now if the last row is being excluded because it is a footnote instead of data you will get a lot of error messages about invalid data on your log.

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 222 views
  • 0 likes
  • 3 in conversation