<?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: Data creation from raw text in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-creation-from-raw-text/m-p/162997#M31586</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are trying to read data created by a report. It would be much easier/better to try and get access to the data used to generate this report. It is possible to read such data but it can take up quite a bit of time to get it right and cover every single layout variation.&lt;/P&gt;&lt;P&gt;Below code illustrates how it could be done. It also shows for the second last transaction (ACCOUNT VERIFY) how the report layout can vary creating additional cases to be dealt with - so additional checks and input statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In short: It could become quite labor intensive to get this 100% right for your real data and it will only work for the report "at hand". If you then want to re-run your code for a later report there might be another "layout" in it for which you haven't coded yet.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data sample(drop=_exp);&lt;/P&gt;&lt;P&gt;&amp;nbsp; attrib&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; account_nr length=$19&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; marker length=$2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; transaction_dt length=8 format=date9.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; text length=$200&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain account_nr;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile 'c:\test\sampledata.txt' truncover dlm=' ';&lt;/P&gt;&lt;P&gt;&amp;nbsp; input @23 transaction_dt ?? :ddmmyy10. @;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if not missing(transaction_dt) then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if anydigit(_infile_)=2 then input account_nr $ 2-20 @;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input @22 marker @32 x1 :best32. x2 :comma32.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input @;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _exp=find(_infile_,'*EXP DATE INVALID OR EXPIRED','i');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _exp&amp;gt;0 then input @_exp p_col $40.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input text $200.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 09 Nov 2014 20:43:37 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2014-11-09T20:43:37Z</dc:date>
    <item>
      <title>Data creation from raw text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-creation-from-raw-text/m-p/162996#M31585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have attached 2 files, the txt file is a flat file which contains data in multiple rows. The good thing is that it is fixed width kind of a data. Have used input to gather information, but getting it beyond one row is turning out to be difficult.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The way in which i need is in the attached excel. Will greatly appreciate any help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ketan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Nov 2014 17:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-creation-from-raw-text/m-p/162996#M31585</guid>
      <dc:creator>enigma84</dc:creator>
      <dc:date>2014-11-09T17:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Data creation from raw text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-creation-from-raw-text/m-p/162997#M31586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are trying to read data created by a report. It would be much easier/better to try and get access to the data used to generate this report. It is possible to read such data but it can take up quite a bit of time to get it right and cover every single layout variation.&lt;/P&gt;&lt;P&gt;Below code illustrates how it could be done. It also shows for the second last transaction (ACCOUNT VERIFY) how the report layout can vary creating additional cases to be dealt with - so additional checks and input statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In short: It could become quite labor intensive to get this 100% right for your real data and it will only work for the report "at hand". If you then want to re-run your code for a later report there might be another "layout" in it for which you haven't coded yet.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data sample(drop=_exp);&lt;/P&gt;&lt;P&gt;&amp;nbsp; attrib&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; account_nr length=$19&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; marker length=$2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; transaction_dt length=8 format=date9.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; text length=$200&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain account_nr;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile 'c:\test\sampledata.txt' truncover dlm=' ';&lt;/P&gt;&lt;P&gt;&amp;nbsp; input @23 transaction_dt ?? :ddmmyy10. @;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if not missing(transaction_dt) then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if anydigit(_infile_)=2 then input account_nr $ 2-20 @;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input @22 marker @32 x1 :best32. x2 :comma32.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input @;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _exp=find(_infile_,'*EXP DATE INVALID OR EXPIRED','i');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _exp&amp;gt;0 then input @_exp p_col $40.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input text $200.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Nov 2014 20:43:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-creation-from-raw-text/m-p/162997#M31586</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-11-09T20:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: Data creation from raw text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-creation-from-raw-text/m-p/162998#M31587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I gotta say data is very dirty .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename x 'c:\temp\sampledata.txt';&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt; infile x dlm=' ' expandtabs truncover;&lt;/P&gt;&lt;P&gt; input @;&amp;nbsp; &lt;/P&gt;&lt;P&gt; length a1-a16 $ 200;&lt;/P&gt;&lt;P&gt; retain a1-a16;&lt;/P&gt;&lt;P&gt; if prxmatch('/^\s+\d{4}\-\d{4}\-\d{4}\-\d{4}/',_infile_) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input (a1-a5) ($) a6 &amp;amp; $ (a8-a14) ($) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; a7=scan(a6,-1,' ');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; a6=substr(a6,1,findc(strip(a6),' ','b'));&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if prxmatch('/\d\d\/\d\d\/\d\d/',_infile_) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input (a2-a5) ($) a6 &amp;amp; $ (a8-a14) ($) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if anyalpha(a5) then return;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; a7=scan(a6,-1,' ');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; a6=substr(a6,1,findc(strip(a6),' ','b'));&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if&amp;nbsp; left(_infile_) eq: '*' then a16=_infile_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if upcase(left(_infile_)) eq: 'PAYMENT' then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if anydigit(a13)=1 then do;a14=a13;a13=' ';end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; a15=_infile_; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if not anyalpha(a5) then output; call missing(a16);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Nov 2014 12:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-creation-from-raw-text/m-p/162998#M31587</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-11-10T12:54:06Z</dc:date>
    </item>
  </channel>
</rss>

