<?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: Extract data from messy text file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-data-from-messy-text-file/m-p/531583#M145522</link>
    <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  array columns(3) $100 column1-column3;
  keep column1-column3;
  do until(0);
    infile cards eof=done;
    input;
    if _infile_=:'@' then do;
      column1=_infile_;
      colno=.;
      call missing(column2,column3);
      end;
    else do;
      if _infile_=:':50H' then
        colno=2;
      else if _infile_=:':21:' then
        colno=3;
      if not missing(colno) then
        call catx(' ',columns(colno),_infile_);
      if _infile_=:':71A:' then do;
        output;
        call missing(column3);
        end;
      end;
    end;
done:
cards;
@20111819
:20:BFSC
:28ABC
:50H:/191919
Amazon
Sydney
Australia
:21:AU111
:23E:ABC
:24CEF
:71A:April
:21:AU222
:23E:ABC
:24CEF
:71A:April
:21:AU333
:23E:ABC
:24CEF
:71A:April
@20111820
:20:BFSC
:28ABC
:50H:/191919
Amazon2
Sydney
Australia
:21:AU111
:23E:ABC
:24CEF
:71A:April
:21:AU222
:23E:ABC
:24CEF
:71A:April
:21:AU333
:23E:ABC
:24CEF
:71A:April
;run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 31 Jan 2019 08:28:29 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2019-01-31T08:28:29Z</dc:date>
    <item>
      <title>Extract data from messy text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-data-from-messy-text-file/m-p/531579#M145519</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really need help asap with one of the queries related to sas data extract.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Background:I have one input text file that contains data related to transactions which is spread across multiple lines having no delimiters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically in first column I want text starting with&amp;nbsp;@ until end of line;&lt;/P&gt;&lt;P&gt;in second column text starting with :50:H until :21:&lt;/P&gt;&lt;P&gt;in third column text stating with :21: until:71A: This will repeat until all :21: are considered in expected outcome&lt;/P&gt;&lt;P&gt;Sample data:&lt;/P&gt;&lt;P&gt;@20111819&lt;BR /&gt;:20:BFSC&lt;BR /&gt;:28:DABC&lt;BR /&gt;:50H:/191919&lt;BR /&gt;Amazon&lt;BR /&gt;Sydney&lt;BR /&gt;Australia&lt;BR /&gt;:21:AU111&lt;BR /&gt;:23E:ABC&lt;BR /&gt;:24C:DEF&lt;BR /&gt;:71A:April&lt;BR /&gt;:21:AU222&lt;BR /&gt;:23E:ABC&lt;BR /&gt;:24C:DEF&lt;BR /&gt;:71A:April&lt;BR /&gt;:21:AU333&lt;BR /&gt;:23E:ABC&lt;BR /&gt;:24C:DEF&lt;BR /&gt;:71A:April&lt;BR /&gt;@20111820&lt;BR /&gt;:20:BFSC&lt;BR /&gt;:28:DABC&lt;BR /&gt;:50H:/191919&lt;BR /&gt;Amazon2&lt;BR /&gt;Sydney&lt;BR /&gt;Australia&lt;BR /&gt;:21:AU111&lt;BR /&gt;:23E:ABC&lt;BR /&gt;:24C:DEF&lt;BR /&gt;:71A:April&lt;BR /&gt;:21:AU222&lt;BR /&gt;:23E:ABC&lt;BR /&gt;:24C:DEF&lt;BR /&gt;:71A:April&lt;BR /&gt;:21:AU333&lt;BR /&gt;:23E:ABC&lt;BR /&gt;:24C:DEF&lt;BR /&gt;:71A:April&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected Output:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Column1&lt;/TD&gt;&lt;TD&gt;Column2&lt;/TD&gt;&lt;TD&gt;Column3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;@20111819&lt;/TD&gt;&lt;TD&gt;:50H:/191919&lt;BR /&gt;Amazon&lt;BR /&gt;Sydney&lt;BR /&gt;Australia&lt;/TD&gt;&lt;TD&gt;:21:AU111&lt;BR /&gt;:23E:ABC&lt;BR /&gt;:24C:DEF&lt;BR /&gt;:71A:April&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;@20111819&lt;/TD&gt;&lt;TD&gt;:50H:/191919&lt;BR /&gt;Amazon&lt;BR /&gt;Sydney&lt;BR /&gt;Australia&lt;/TD&gt;&lt;TD&gt;:21:AU222&lt;BR /&gt;:23E:ABC&lt;BR /&gt;:24C:DEF&lt;BR /&gt;:71A:April&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;@20111819&lt;/TD&gt;&lt;TD&gt;:50H:/191919&lt;BR /&gt;Amazon&lt;BR /&gt;Sydney&lt;BR /&gt;Australia&lt;/TD&gt;&lt;TD&gt;:21:AU333&lt;BR /&gt;:23E:ABC&lt;BR /&gt;:24C:DEF&lt;BR /&gt;:71A:April&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;@20111820&lt;/TD&gt;&lt;TD&gt;:50H:/191919&lt;BR /&gt;Amazon2&lt;BR /&gt;Sydney&lt;BR /&gt;Australia&lt;/TD&gt;&lt;TD&gt;:21:AU111&lt;BR /&gt;:23E:ABC&lt;BR /&gt;:24C:DEF&lt;BR /&gt;:71A:April&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;@20111820&lt;/TD&gt;&lt;TD&gt;:50H:/191919&lt;BR /&gt;Amazon2&lt;BR /&gt;Sydney&lt;BR /&gt;Australia&lt;/TD&gt;&lt;TD&gt;:21:AU222&lt;BR /&gt;:23E:ABC&lt;BR /&gt;:24C:DEF&lt;BR /&gt;:71A:April&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;@20111820&lt;/TD&gt;&lt;TD&gt;:50H:/191919&lt;BR /&gt;Amazon2&lt;BR /&gt;Sydney&lt;BR /&gt;Australia&lt;/TD&gt;&lt;TD&gt;:21:AU333&lt;BR /&gt;:23E:ABC&lt;BR /&gt;:24C:DEF&lt;BR /&gt;:71A:April&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Can someone please help me with this.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 07:54:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-data-from-messy-text-file/m-p/531579#M145519</guid>
      <dc:creator>rohini05</dc:creator>
      <dc:date>2019-01-31T07:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from messy text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-data-from-messy-text-file/m-p/531581#M145521</link>
      <description>&lt;P&gt;Pleas use the {i} button for posting example text; the main posting window scrambles your data (as seen by the emoticons).&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 08:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-data-from-messy-text-file/m-p/531581#M145521</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-31T08:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from messy text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-data-from-messy-text-file/m-p/531583#M145522</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  array columns(3) $100 column1-column3;
  keep column1-column3;
  do until(0);
    infile cards eof=done;
    input;
    if _infile_=:'@' then do;
      column1=_infile_;
      colno=.;
      call missing(column2,column3);
      end;
    else do;
      if _infile_=:':50H' then
        colno=2;
      else if _infile_=:':21:' then
        colno=3;
      if not missing(colno) then
        call catx(' ',columns(colno),_infile_);
      if _infile_=:':71A:' then do;
        output;
        call missing(column3);
        end;
      end;
    end;
done:
cards;
@20111819
:20:BFSC
:28ABC
:50H:/191919
Amazon
Sydney
Australia
:21:AU111
:23E:ABC
:24CEF
:71A:April
:21:AU222
:23E:ABC
:24CEF
:71A:April
:21:AU333
:23E:ABC
:24CEF
:71A:April
@20111820
:20:BFSC
:28ABC
:50H:/191919
Amazon2
Sydney
Australia
:21:AU111
:23E:ABC
:24CEF
:71A:April
:21:AU222
:23E:ABC
:24CEF
:71A:April
:21:AU333
:23E:ABC
:24CEF
:71A:April
;run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Jan 2019 08:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-data-from-messy-text-file/m-p/531583#M145522</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-01-31T08:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from messy text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-data-from-messy-text-file/m-p/531584#M145523</link>
      <description>&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data want;&lt;BR /&gt;  length line $2000;&lt;BR /&gt;  infile "&amp;amp;_sasws_./temp.txt" dlm="¬" end=lastrec;&lt;BR /&gt;  input line $;&lt;BR /&gt;  line=strip(line);&lt;BR /&gt;  array vs{3} $2000;&lt;BR /&gt;  retain vs: i;&lt;BR /&gt;  if _n_=1 then i=1;&lt;BR /&gt;  else if char(line,1)="@" then do;&lt;BR /&gt;    output;&lt;BR /&gt;    i=1;&lt;BR /&gt;    call missing(of vs{*});&lt;BR /&gt;    vs{i}=line;&lt;BR /&gt;  end;&lt;BR /&gt;  else if substr(line,1,3)=":50" then i=2;&lt;BR /&gt;  else if substr(line,1,3)=":21" then i=3;&lt;BR /&gt;  vs{i}=cats(vs{i},line);&lt;BR /&gt;  if lastrec then output;&lt;BR /&gt;run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Jan 2019 08:32:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-data-from-messy-text-file/m-p/531584#M145523</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-01-31T08:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from messy text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-data-from-messy-text-file/m-p/531589#M145527</link>
      <description>Thanks a ton! I will apply the same at my work tomorrow.</description>
      <pubDate>Thu, 31 Jan 2019 09:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-data-from-messy-text-file/m-p/531589#M145527</guid>
      <dc:creator>rohini05</dc:creator>
      <dc:date>2019-01-31T09:06:21Z</dc:date>
    </item>
  </channel>
</rss>

