<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: import .txt file with the first line as title and descritpions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633922#M188113</link>
    <description>&lt;P&gt;If this is a one-off thing, using a preliminary step to remove the top three lines and then proc import makes sense. But if you have to run that import repeatedly, you will have to use a data step anyway to achieve consistent results, and then you can solve everything in one step by using the firstobs= option.&lt;/P&gt;</description>
    <pubDate>Sun, 22 Mar 2020 08:02:18 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-03-22T08:02:18Z</dc:date>
    <item>
      <title>import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633745#M188013</link>
      <description>&lt;P&gt;I have a .txt data file like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Title
desc1
date
name type bday
alan card 11/15/1950
bob e-card 08/23/1951&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to read into SAS ignoring the line1-3 and get the data like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;name type bday
alan card 11/15/1950
bob e-card 08/23/1951&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried proc import or infile, but none of them succeeded.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile = 'text.txt'
 out = data1
 dbms = dlm replace;
 delimiter = ' ';
 getnames= yes;
 namerow= 4;
 datarow= 5;
run;

data data2;
	infile 'text.txt' dsd dlm=' ' truncover firstobs=4;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I was not able to figure out how to assign the starting row to read, and at the same time how to get the column names.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks ahead for any suggestions!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2020 22:55:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633745#M188013</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2020-03-20T22:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633756#M188019</link>
      <description>&lt;P&gt;Why are you asking SAS to guess how to read a file that only has three variables?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile cards dsd dlm=' ' truncover ;
  length name $20 type $10 bday 8 ;
  if _n_= 1 then input title $200. / desc $200. / date :mmddyy. / ;
  input name type bday :mmddyy.;
  format bday date date9.;
  retain title desc date;
cards;
BDAY CARDS
bla bla
03/20/2020
name type bday
alan card 11/15/1950
bob e-card 08/23/1951
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    name     type       bday         title        desc        date

 1     alan    card      15NOV1950    BDAY CARDS    bla bla    20MAR2020
 2     bob     e-card    23AUG1951    BDAY CARDS    bla bla    20MAR2020
&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Mar 2020 23:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633756#M188019</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-20T23:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633759#M188022</link>
      <description>Thanks.&lt;BR /&gt;&lt;BR /&gt;I don't need the top three lines. And I actually have a data set with hundreds of columns, so I want to avoid using inputting column names manually. The best way is just to read the data existed in the .txt file.</description>
      <pubDate>Fri, 20 Mar 2020 23:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633759#M188022</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2020-03-20T23:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633761#M188024</link>
      <description>&lt;P&gt;Proc Import will ONLY get the variable names if they are the first row (at least in the current incarnation).&lt;/P&gt;
&lt;P&gt;If there is only one block of the 3 lines you don't want then I would make a copy of the file deleting those 3 lines and import the rest as a start.&lt;/P&gt;
&lt;P&gt;If you are going to read multiple files in this format in the future then copy the code from the LOG that Proc Import generates, paste into the Editor and save the program. Clean up things like line numbers ans such. Then add the Firstobs=5 to read the next file of the same format. Just change the infile to match the new file and the output data set name(if desired).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have multiple blocks of the Title, Desc and Date in the middle of the file then you need to provide some way to tell Title and Desc from a Name and then parse the data file a bit. If you search the forum for "input _infile_ @;" you will likely find some examples parsing such a file.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2020 23:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633761#M188024</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-20T23:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633763#M188026</link>
      <description>&lt;P&gt;Not sure a TEXT file is the best format to store data if you don't already know what data types the text is supposed to represent.&amp;nbsp; But if you want to let PROC IMPORT guess at how to define the variables then just tell it NOT to read the names.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile=text dbms=dlm out=want replace ;
  delimiter=' ';
  datarow=5;
  getnames=NO;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can always read the names yourself and then use them to rename the variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile=text dbms=dlm out=headers replace;
  delimiter=' ';
  datarow=4;
  getnames=NO;
run;
proc transpose data=headers(obs=1) out=names ;
  var _all_;
run;
filename code temp;
data _null_;
 set names end=eof;
 file code;
 if _n_=1 then put 'rename ';
 put _name_ '=' col1 :$quote. +(-1) 'n' ;
 if eof then put ';';
run;
proc datasets nolist lib=work;
modify want ;
%include code / source2;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    name     type        bday

 1     alan    card      11/15/1950
 2     bob     e-card    08/23/1951
&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Mar 2020 23:33:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633763#M188026</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-20T23:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633782#M188032</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215142"&gt;@leehsin&lt;/a&gt;&amp;nbsp;&amp;nbsp;If this is really only about skipping the first 3 lines then you could just read/write the text file skipping the first 3 lines. That's what below tested code does.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* create sample external file HAVE */
filename have temp lrecl=100;
data _null_;
  file have;
  infile datalines;
  input;
  _infile_=strip(_infile_);
  put _infile_;
  datalines;
Title
desc1
date
name type bday
alan card 11/15/1950
bob e-card 08/23/1951
;

/* write source external file HAVE to intermediary external file INTER
   - skip first 3 rows
*/
filename inter temp lrecl=100;
data _null_;
  file inter;
  infile have firstobs=4;
  input;
  put _infile_;
run;
filename have clear;

/* use proc import to read external file INTER */
proc import 
 file = inter
 out = want
 dbms = dlm 
 replace;
 delimiter = ' ';
 getnames= yes;
 guessingrows=max;
run;
filename inter clear;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 206px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/37179iFDB6E85E6F8053E6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Mar 2020 02:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633782#M188032</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-22T02:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633789#M188038</link>
      <description>&lt;P&gt;Try the default proc import, remove the namerow &amp;nbsp;&amp;amp; getnames option. If that doesn’t work, please post the log or indicate what didn’t work.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215142"&gt;@leehsin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a .txt data file like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Title
desc1
date
name type bday
alan card 11/15/1950
bob e-card 08/23/1951&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to read into SAS ignoring the line1-3 and get the data like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;name type bday
alan card 11/15/1950
bob e-card 08/23/1951&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I tried proc import or infile, but none of them succeeded.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile = 'text.txt'
 out = data1
 dbms = dlm replace;
 delimiter = ' ';
 getnames= yes;
 namerow= 4;
 datarow= 5;
run;

data data2;
	infile 'text.txt' dsd dlm=' ' truncover firstobs=4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I was not able to figure out how to assign the starting row to read, and at the same time how to get the column names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks ahead for any suggestions!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Mar 2020 03:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633789#M188038</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-21T03:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633814#M188052</link>
      <description>&lt;P&gt;Copy the file to a temporary file that the IMPORT procedure can more easily use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mydata 'c:\temp\mydata.txt';
filename nohead temp;

data _null_;
  infile mydata;
    file nohead;

  input;
  if _n_ &amp;gt; 3;
  put _infile_;
run;


proc import 
 datafile = nohead
 out = data1
 dbms = dlm replace
;
 delimiter = ' ';
 getnames= yes;
run;

filename mydata clear;
filename nohead clear;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;lt;soapbox&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;SPAN style="font-family: inherit;"&gt;GETNAMES causes the procedure to presume row is the header row containing field name. There are no options for also specifying a header row as anything other than the first row.&lt;BR /&gt;Should SAS add an option NAMEROW= ?&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN style="font-family: inherit;"&gt;Output of an operating system command can be piped to the IMPORT procedure.&amp;nbsp; Problem is that IMPORT needs random access that PIPE does not have.&lt;/SPAN&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename nohead pipe "more +3 c:\temp\mydata.txt";&lt;BR /&gt;proc import dbms=dlm datafile=nohead replace out=data2;&lt;BR /&gt;--- LOG ---&lt;BR /&gt;ERROR: Random access not allowed.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
Should SAS update Proc IMPORT to be able to process text data from a stream?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;&amp;lt;/soapbox&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Mar 2020 11:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633814#M188052</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-03-21T11:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633909#M188105</link>
      <description>&lt;P&gt;It can be replicated by the following steps:&lt;/P&gt;&lt;P&gt;1) Use Notepad to save the following text as a .txt file in your folder:&lt;/P&gt;&lt;P&gt;Title&lt;BR /&gt;desc1&lt;BR /&gt;date&lt;BR /&gt;name type bday&lt;BR /&gt;alan card 11/15/1950&lt;BR /&gt;bob e-card 08/23/1951&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Assign macro &amp;amp;path. with your path. Use the following code to import the attached .txt file:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path = "yourpath";

proc import datafile = "&amp;amp;path.\text.txt"
out = data1
dbms = dlm replace;
delimiter = ' ';
getnames= yes;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;SAS read the text successfully. 5 rows and 3 columns created in work.data1 from the text.txt file. But the value in work.data1 is:&lt;/P&gt;&lt;P&gt;column name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Title&amp;nbsp; &amp;nbsp;VAR2&amp;nbsp; &amp;nbsp;VAR3&lt;/P&gt;&lt;P&gt;row1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; desc1&lt;/P&gt;&lt;P&gt;row2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date&lt;/P&gt;&lt;P&gt;row3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; name&amp;nbsp; &amp;nbsp;type&amp;nbsp; &amp;nbsp; &amp;nbsp;bday&lt;/P&gt;&lt;P&gt;row4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alan&amp;nbsp; &amp;nbsp; &amp;nbsp;card&amp;nbsp; &amp;nbsp; &amp;nbsp;11/15/1950&lt;/P&gt;&lt;P&gt;row5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bob&amp;nbsp; &amp;nbsp; &amp;nbsp;e-card&amp;nbsp; &amp;nbsp;08/23/1951&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want a data like this, only have three columns and three rows including the column names:&lt;/P&gt;&lt;P&gt;column name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;name&amp;nbsp; &amp;nbsp;type&amp;nbsp; &amp;nbsp; &amp;nbsp;bday&lt;/P&gt;&lt;P&gt;row2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alan&amp;nbsp; &amp;nbsp; &amp;nbsp;card&amp;nbsp; &amp;nbsp; &amp;nbsp;11/15/1950&lt;/P&gt;&lt;P&gt;row3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bob&amp;nbsp; &amp;nbsp; &amp;nbsp;e-card&amp;nbsp; &amp;nbsp;08/23/1951&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If use the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile = "&amp;amp;path.\text.txt"
 out = data1
 dbms = dlm replace;
 delimiter = ' ';
 getnames= yes;
 namerow= 4;
 datarow= 5;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;then failed with the error message:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;110  proc import datafile = "&amp;amp;path.\text.txt"
111   out = data1
112   dbms = dlm replace;
NOTE: The previous statement has been deleted.
NOTE: The previous statement has been deleted.
113   delimiter = ' ';
114   getnames= yes;
115   namerow= 4;
      -------
      180
ERROR 180-322: Statement is not valid or it is used out of proper order.

116   datarow= 5;
117  run;


NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Mar 2020 01:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633909#M188105</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2020-03-22T01:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633913#M188107</link>
      <description>&lt;P&gt;As far as I can see there isn't a namerow option. I can find the data row but it still gets the names from the first row.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;solution to read the names and data separately is one option. Another is to recreate the file removing the first few lines and then read it in using PROC IMPORT.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Here's an example of how that can get done. This is designed for the temp file to go the work folder so the temp file doesn't stick around if this is something going into production or for cleaner code.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let work_path=%sysfunc(pathname(work));

data _null_;
infile '/home/fkhurshed/Demo1/demo.txt.sas';
file "&amp;amp;work_path./temp.txt";
input ;
if _n_ &amp;lt; 4 then delete;
else put _infile_;
run;

proc import out=want datafile="&amp;amp;work_path./temp.txt" dbms=dlm replace;
delimiter = ' ';
getnames=yes;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Mar 2020 02:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633913#M188107</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-22T02:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633922#M188113</link>
      <description>&lt;P&gt;If this is a one-off thing, using a preliminary step to remove the top three lines and then proc import makes sense. But if you have to run that import repeatedly, you will have to use a data step anyway to achieve consistent results, and then you can solve everything in one step by using the firstobs= option.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Mar 2020 08:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/633922#M188113</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-22T08:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634577#M188351</link>
      <description>&lt;P&gt;The .txt file is my source data and actually contains large amount of columns and rows. It has headers (title, descriptions, and even tail at the bottom of the data body). There are many .txt files to be imported. To manually input the names of column is not practical. The example I presented here is just a simplified one that represent the structure of .txt data file. If a program can import this example .txt file and output the SAS data that I want, my mission is accomplished. For now, I have to manually read these .txt files using Excel, delete the unwanted parts, and save it into a csv file,&amp;nbsp; then these .csv files are subjected for SAS to import.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for all the suggestions and helps!&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 20:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634577#M188351</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2020-03-24T20:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634599#M188356</link>
      <description>&lt;P&gt;Do all these txt files share the same structure?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 22:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634599#M188356</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-24T22:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634600#M188357</link>
      <description>&lt;P&gt;There were several solutions posted that do not require manual intervention. Did none of them work for you at all?&lt;BR /&gt;I tested mine with your exact posted and it imported the file exactly as requested, though it's hard coded to ignore the first 4 lines in the header. It's possible to make that dynamic, if the number of lines to ignore changes, but since you were providing 4/5 to the PROC IMPORT I assumed that was fixed parameters. It's easy enough to make it a macro as well to pass the file name and the number of header lines if that's another approach.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215142"&gt;@leehsin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The .txt file is my source data and actually contains large amount of columns and rows. It has headers (title, descriptions, and even tail at the bottom of the data body). There are many .txt files to be imported. To manually input the names of column is not practical. The example I presented here is just a simplified one that represent the structure of .txt data file. If a program can import this example .txt file and output the SAS data that I want, my mission is accomplished. For now, I have to manually read these .txt files using Excel, delete the unwanted parts, and save it into a csv file,&amp;nbsp; then these .csv files are subjected for SAS to import.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for all the suggestions and helps!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 22:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634600#M188357</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-24T22:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634654#M188381</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename D "%sysfunc(pathname(WORK))/t.txt";

%* Create data file;
data  _null_;
   file D;
   put 'Title'
     / 'desc1'
     / 'date'
     / 'name type bday'
     / 'alan card 11/15/1950'
     / 'bob e-card 08/23/1951';
run;

%*  Read variable names and create renaming statement;
data _null_;
  infile D firstobs=4;
  input;
  length RENAMELIST $4000;
  do I= 1 to countw(_INFILE_);
     RENAMELIST=catx(' ',RENAMELIST,(catt('VAR',I,'=',scan(_INFILE_,I))));
  end;
  call symput('renamelist',RENAMELIST);
  stop;
run;

%* Read data;
proc import datafile = D
            out      = WANT
            dbms     = dlm 
            replace;
 delimiter = ' ';
 getnames  = no;
 datarow   = 5;
run;

%* Rename columns;
proc datasets nolist;
  modify WANT ;
  rename &amp;amp;renamelist.;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;TABLE class="table" style="border-collapse: collapse; border-spacing: 0px; margin-bottom: 1em; border-width: 1px 0px 0px 1px; border-style: solid; border-color: #c1c1c1; border-image: initial; margin-left: auto; margin-right: auto; color: #000000; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: center; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #fafbfe; text-decoration-style: initial; text-decoration-color: initial;" aria-label="Data Set WORK.WANT"&gt;&lt;CAPTION aria-label="Data Set WORK.WANT"&gt;&amp;nbsp;&lt;/CAPTION&gt;&lt;COLGROUP&gt;&lt;COL style="border-left: 1px solid #c1c1c1; border-right: 0px solid #c1c1c1;" /&gt;&lt;COL style="border-left: 1px solid #c1c1c1; border-right: 0px solid #c1c1c1;" /&gt;&lt;COL style="border-left: 1px solid #c1c1c1; border-right: 0px solid #c1c1c1;" /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR style="border-top: 1px solid #c1c1c1; border-bottom: 0px solid #c1c1c1;"&gt;
&lt;TH class="header" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #edf2f9; border-color: #b0b7bb; border-style: solid; border-width: 0px 1px 1px 0px; color: #112277; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: bold;" scope="col"&gt;name&lt;/TH&gt;
&lt;TH class="header" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #edf2f9; border-color: #b0b7bb; border-style: solid; border-width: 0px 1px 1px 0px; color: #112277; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: bold;" scope="col"&gt;type&lt;/TH&gt;
&lt;TH class="r header" style="text-align: right; padding: 3px 6px; vertical-align: top; background-color: #edf2f9; border-color: #b0b7bb; border-style: solid; border-width: 0px 1px 1px 0px; color: #112277; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: bold;" scope="col"&gt;bday&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR style="border-top: 1px solid #c1c1c1; border-bottom: 0px solid #c1c1c1;"&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;alan&lt;/TD&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;card&lt;/TD&gt;
&lt;TD class="r data" style="text-align: right; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;11/15/1950&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="border-top: 1px solid #c1c1c1; border-bottom: 0px solid #c1c1c1;"&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;bob&lt;/TD&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;e-card&lt;/TD&gt;
&lt;TD class="r data" style="text-align: right; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;08/23/1951&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 09:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634654#M188381</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-25T09:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634839#M188438</link>
      <description>Thank you, ChrisNZ !&lt;BR /&gt;If I had a extra line below the last line as a tail and I wanted to exclude it (different .txt files have different amount of the rows, so that we can't identify and use the row number to locate the tail for all .txt files), what will the code look like?</description>
      <pubDate>Wed, 25 Mar 2020 17:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634839#M188438</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2020-03-25T17:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634861#M188453</link>
      <description>&lt;P&gt;In the INFILE statement, use the end= option to define a flag variable; use this flag variable to not output the last line:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
infile '/home/fkhurshed/Demo1/demo.txt.sas' end=done;
file "&amp;amp;work_path./temp.txt";
input ;
if _n_ &amp;lt; 4 or done then delete;
else put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Mar 2020 18:34:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634861#M188453</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-25T18:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634942#M188480</link>
      <description>&lt;P&gt;Since you opted to using proc import, you don't have many ways to customise the way you read the file.&lt;/P&gt;
&lt;P&gt;Your last row will have to be deleted manually, if proc import includes it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data WANT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set WANT end=LASTOBS;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if LASTOBS then delete;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When using the infile statement, there are many options, such as the one showed by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 01:57:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/634942#M188480</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-26T01:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: import .txt file with the first line as title and descritpions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/635040#M188519</link>
      <description>&lt;P&gt;It can be accomplished now with my task of importing .TXT files with head lines and tail lines.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for everyone's help!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 13:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-file-with-the-first-line-as-title-and-descritpions/m-p/635040#M188519</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2020-03-26T13:21:21Z</dc:date>
    </item>
  </channel>
</rss>

