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;
try
data test;
infile "H:\file.tsv" obs=1 lrec=20000 pad;
input lines $1-20000;
run;
try
data test;
infile "H:\file.tsv" obs=1 lrec=20000 pad;
input lines $1-20000;
run;
It was the pad option that did it! Thanks so much for your quick response. Much appreciated.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.