DATA Step, Macro, Functions and more

How can I infile the header as data?

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

How can I infile the header as data?

I'm trying to read a tab delimited file with the first row containing a header.  My goal is to get the header line only for a large number of datasets that vary in size and construction. Because the header lines are variable in length and can contain hundreds of fields, I can't set the lrecl to the exact width of any header line.  When the input length upper limit is less than the length of the header line, the header line imports but is short of the last field; however, when I make the length longer than the length of the header line, so that it goes into line 2, it ignores the header line completely, and acts as though line 2 is the first line of the file.

 

The code below shows basically what I'm trying to do.  I've tried everything I can think of without success.  Any feedback is appreciated.

 

data test;
infile "H:\file.tsv" firstobs=1;
input lines $1-20000;
if _N_ eq 1;
run;


Accepted Solutions
Solution
‎07-26-2016 06:51 PM
Super User
Posts: 10,466

Re: How can I infile the header as data?

try

 

data test;
infile "H:\file.tsv" obs=1 lrec=20000 pad;
input lines $1-20000; 

run;

View solution in original post


All Replies
Solution
‎07-26-2016 06:51 PM
Super User
Posts: 10,466

Re: How can I infile the header as data?

try

 

data test;
infile "H:\file.tsv" obs=1 lrec=20000 pad;
input lines $1-20000; 

run;

Contributor
Posts: 26

Re: How can I infile the header as data?

It was the pad option that did it!  Thanks so much for your quick response.  Much appreciated.

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 593 views
  • 0 likes
  • 2 in conversation