<?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: Stuck trying to import/input an oddly delimited text file. INPUT or parse post-PROC IMPORT? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441257#M110357</link>
    <description>&lt;P&gt;Looks like you have multiple datasets/files defined in this single document.&amp;nbsp; There appear to be headers using **** between the files. It might just be easier to manually split the file into separate files for each one, but you could probably design a method to detect those also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have mainly D and V records and a few U records which it is not immediately obvious if they are useful for anything. The tricky part will be if you want to also read the multiple line descriptions that follow the D records and also some of the V records also appear to be split over multiple lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try something like this to start and then see if you can either make it handle more variation, or just manually update the results with more details than you could pull with the program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data variables (keep=name length start range label )
        values (keep=name vdescr vstart vlabel)
;
  length name $32 length start 8 range $20 label $256 ;
  length vdescr $256 vstart $32 vlabel $256 ; 
  retain NAME VDESCR;
  infile 'myfile.txt' truncover ;
  input @ ;
  if _infile_=:'D' then do ;
   input name start length range / label $256. ;
   output variables ;&lt;BR /&gt;   vdescr = ' ';
  end;
  if _infile_=:'V' then do;
    if _infile_^=: 'V   ' then input @2 vdescr $256. ;
    else do;
      vstart = left(substr(_infile_,2,12));
      vlabel = left(substr(_infile_,13));
      output values;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Mar 2018 16:24:29 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-03-01T16:24:29Z</dc:date>
    <item>
      <title>Stuck trying to import/input an oddly delimited text file. INPUT or parse post-PROC IMPORT?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441223#M110338</link>
      <description>&lt;P&gt;Hey all,&lt;/P&gt;&lt;P&gt;I'm a little stuck with how best to approach the input of a text file.&lt;/P&gt;&lt;P&gt;Here's what my data looks like -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;HOUSEHOLD RECORD&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;DATA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SIZE&amp;nbsp;&amp;nbsp; BEGIN RANGE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;D HRECORD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; (1:1)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;U All households&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;V&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 .Household record&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;D H_SEQ&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp; (00001:99999)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Household sequence number&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;V All households&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;V&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 00001- .Household sequence number&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;V&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 99999&amp;nbsp; .&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;D HHPOS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&amp;nbsp; (00:00)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Trailer portion of unique household ID. &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;00 for HH record. Same function in &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;family record is field FFPOS (01-39). &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;Same function in person record is PPPOS &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;(41-79).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3" face="arial,helvetica,sans-serif"&gt;Following "D " is always the variable name ("&lt;FONT size="1 2 3 4 5 6 7" face="helvetica"&gt;HRECORD&lt;/FONT&gt;"), which I want to input. Following the variable is the length ("size" column) which I also wish to input. "U" designates the universe; I want to keep that string. "V" designates the values for that variable, which I also want bring in. A variation of this structure, is when the "D" row is followed by a variable description, (between D and U or V). &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3" face="arial,helvetica,sans-serif"&gt;&lt;BR /&gt;I'm not exactly sure how to import/input this text file considering it's data structure. A PROC IMPORT will bring everything in, but into just one column and some descriptions are truncated/cut off. I've thought about using character functions to start parsing the data. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3" face="arial,helvetica,sans-serif"&gt;The goal is to have a data set with the following columns: Var_Name, Length, Description, Universe, and Values.&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3" face="arial,helvetica,sans-serif"&gt;Any insight? &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3" face="arial,helvetica,sans-serif"&gt;(SAS 9.4 TS Level 1M4, Enterprise Guide 7.1) &lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 15:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441223#M110338</guid>
      <dc:creator>deltron</dc:creator>
      <dc:date>2018-03-01T15:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Stuck trying to import/input an oddly delimited text file. INPUT or parse post-PROC IMPORT?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441234#M110344</link>
      <description>&lt;P&gt;There is no simple method I am afraid, simple methods are only available for standard file formats.&lt;/P&gt;
&lt;P&gt;Read in the data using a datastep and infile.&amp;nbsp; Input the text record as a whole, then post process it.&amp;nbsp; E.g.&lt;/P&gt;
&lt;PRE&gt;data want;
  infile "youdata.txt";
  input;
  if char(_input_,1)="D" and char(_input_,2)=" " then do;
    ...;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Note, its not even a delimited file!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 15:52:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441234#M110344</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-01T15:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Stuck trying to import/input an oddly delimited text file. INPUT or parse post-PROC IMPORT?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441235#M110345</link>
      <description>&lt;P&gt;Are you asking how to read this data dictionary report into a metadata dataset?&lt;/P&gt;
&lt;P&gt;Or are you asking how to use the information in this report to read the actual data file it is describing?&lt;/P&gt;
&lt;P&gt;Neither look like they are "delimited".&amp;nbsp; Both appear to be using fixed format.&lt;/P&gt;
&lt;P&gt;The data dictionary you posted is just using different record structures on different lines based on what information is on those line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can read this using a data step pretty easily.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 15:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441235#M110345</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-01T15:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Stuck trying to import/input an oddly delimited text file. INPUT or parse post-PROC IMPORT?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441242#M110349</link>
      <description>&lt;P&gt;Yes, I'm asking how to specifically read parts of this data dictionary into a metadata dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 16:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441242#M110349</guid>
      <dc:creator>deltron</dc:creator>
      <dc:date>2018-03-01T16:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Stuck trying to import/input an oddly delimited text file. INPUT or parse post-PROC IMPORT?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441251#M110353</link>
      <description>&lt;P&gt;Thank you. I'll give this a try.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 16:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441251#M110353</guid>
      <dc:creator>deltron</dc:creator>
      <dc:date>2018-03-01T16:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: Stuck trying to import/input an oddly delimited text file. INPUT or parse post-PROC IMPORT?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441257#M110357</link>
      <description>&lt;P&gt;Looks like you have multiple datasets/files defined in this single document.&amp;nbsp; There appear to be headers using **** between the files. It might just be easier to manually split the file into separate files for each one, but you could probably design a method to detect those also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have mainly D and V records and a few U records which it is not immediately obvious if they are useful for anything. The tricky part will be if you want to also read the multiple line descriptions that follow the D records and also some of the V records also appear to be split over multiple lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try something like this to start and then see if you can either make it handle more variation, or just manually update the results with more details than you could pull with the program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data variables (keep=name length start range label )
        values (keep=name vdescr vstart vlabel)
;
  length name $32 length start 8 range $20 label $256 ;
  length vdescr $256 vstart $32 vlabel $256 ; 
  retain NAME VDESCR;
  infile 'myfile.txt' truncover ;
  input @ ;
  if _infile_=:'D' then do ;
   input name start length range / label $256. ;
   output variables ;&lt;BR /&gt;   vdescr = ' ';
  end;
  if _infile_=:'V' then do;
    if _infile_^=: 'V   ' then input @2 vdescr $256. ;
    else do;
      vstart = left(substr(_infile_,2,12));
      vlabel = left(substr(_infile_,13));
      output values;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 16:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441257#M110357</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-01T16:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Stuck trying to import/input an oddly delimited text file. INPUT or parse post-PROC IMPORT?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441310#M110382</link>
      <description>I'll play around with this and see. Thank you for your time.</description>
      <pubDate>Thu, 01 Mar 2018 18:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stuck-trying-to-import-input-an-oddly-delimited-text-file-INPUT/m-p/441310#M110382</guid>
      <dc:creator>deltron</dc:creator>
      <dc:date>2018-03-01T18:10:43Z</dc:date>
    </item>
  </channel>
</rss>

