<?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 string from Swift messages in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275879#M55229</link>
    <description>&lt;P&gt;Even though tag 59 is mandatory, and account no must be attached if known - there is to my knowledge no enforce account no format, like IBAN or BBAN.&lt;/P&gt;
&lt;P&gt;But do you really need to parse the Swift message yourself? If you work with a financial institution they have parsers that interfaces with their payment systems.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jun 2016 06:47:04 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2016-06-08T06:47:04Z</dc:date>
    <item>
      <title>Extract string from Swift messages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275863#M55226</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to extract account number and branch number from the below swift messages. Account number present after :59: - in first input its 12345678 (until space) and branch number after ‘BSB’ is 7654.&lt;/P&gt;
&lt;P&gt;In few records the branch number is prefixed in the account number after :59: as shown in input record 2. (acct # 21345678 BSB# 8765)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Logic rule&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) BSB should be in the :59: message field but not all records have the BSB, few records have just account number followed by account holder name(record 3)&lt;/P&gt;
&lt;P&gt;2) 4 or 6 (with country code) digit numbers followed the text 'BSB' in the :59: field (record 1)&lt;/P&gt;
&lt;P&gt;3) If the account number is greater than 8-digit then first 4 or 6 digit is BSB and the remaining 8 digit is account number (record 2)&lt;/P&gt;
&lt;P&gt;4) acct # always 8-digit and BSB # always 4 or 6 digit&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Record1
:SND:ABCDSASIAXXX :RCV:MNOPIN2SAXXX :20:XY1543514245054 :23B:CRED :32A:12345AUD1073,23 :50K:/1234568 XYZ P.O.BOX 316 ABCD-31952 :52A:DEFGGHRI :53B:/D/1234567800570 :57A:REWSSY2SXXX :59:/12345678 XYSDEF BSB 7654 :70:NOTES TO BANK :71A:ABC

Record2
:SND:ABCDSASIAXXX :RCV:MNOPIN2SAXXX :20:XY1543514245054 :23B:CRED :32A:12345AUD1073,23 :50K:/1234568 XYZ P.O.BOX 316 ABCD-31952 :52A:DEFGGHRI :53B:/D/1234567800570 :57A:REWSSY2SXXX :59:/876521345678 XYSDEF :70:NOTES TO BANK :71A:ABC

Record3
:SND:ABCDSASIAXXX :RCV:MNOPIN2SAXXX :20:XY1543514245054 :23B:CRED :32A:12345AUD1073,23 :50K:/1234568 XYZ P.O.BOX 316 ABCD-31952 :52A:DEFGGHRI :53B:/D/1234567800570 :57A:REWSSY2SXXX :59:/21345678 XYSDEF :70:NOTES TO BANK :71A:ABC
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;I need output as below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Acct_no&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BSB_no&lt;/P&gt;
&lt;P&gt;12345678&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7654&lt;/P&gt;
&lt;P&gt;21345678&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8765&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please advise how to achieve the desired results.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 06:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275863#M55226</guid>
      <dc:creator>angorwat</dc:creator>
      <dc:date>2016-06-08T06:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string from Swift messages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275868#M55228</link>
      <description>&lt;P&gt;a) could you please supply the test data in a code block, so that no smileys are created from the data?&lt;/P&gt;
&lt;P&gt;b) what is the logical rule for the BSB to be present directly after the 59:/ ?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 05:46:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275868#M55228</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-08T05:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string from Swift messages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275879#M55229</link>
      <description>&lt;P&gt;Even though tag 59 is mandatory, and account no must be attached if known - there is to my knowledge no enforce account no format, like IBAN or BBAN.&lt;/P&gt;
&lt;P&gt;But do you really need to parse the Swift message yourself? If you work with a financial institution they have parsers that interfaces with their payment systems.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 06:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275879#M55229</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-06-08T06:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string from Swift messages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275883#M55230</link>
      <description>&lt;P&gt;Hi LinusH,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure about other available system to parse these msg in my &lt;SPAN&gt;institution&lt;/SPAN&gt;. my access level is restricted to this level of data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to do an analysis based on the account numbers linked to other source systems.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 06:57:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275883#M55230</guid>
      <dc:creator>angorwat</dc:creator>
      <dc:date>2016-06-08T06:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string from Swift messages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275884#M55231</link>
      <description>&lt;P&gt;Assume the length of&amp;nbsp;&lt;SPAN&gt;Acct_no was always 8. &amp;nbsp; &amp;nbsp; &amp;nbsp;the length of BSB_no&amp;nbsp;&lt;SPAN&gt;was always 4.&lt;/SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input x $400.;
temp=substr(x,find(x,'59:/')+4);
a=scan(temp,1,' ');
if length(a)=8 then do;
  Acct_no=a;
  BSB_no=substr(temp,find(temp,'BSB')+4,4);
end;
 else do;
  Acct_no=substr(a,5);
  BSB_no=substr(a,1,4);
 end;
drop temp a;
cards;
ND:ABCDSASIAXXX :RCV:MNOPIN2SAXXX :20:XY1543514245054 :23B:CRED :32A:12345AUD1113 :50K:/1234568 XYZ P.O.BOX 316 ABCD-31952 :52ASmiley Very HappyEFGGHRI :53B:/D/1234567800570 :57A:RYWASY2SXXX :59:/12345678 XYSDEF BSB 7654 :70:NOTES TO BANK :71A:ABC
ND:ABCDSASIAXXX :RCV:MNOPIN2SAXXX :20:XY1543514245054 :23B:CRED :32A:12345AUD1073 :50K:/1234568 XYZ P.O.BOX 316 ABCD-31952 :52ASmiley Very HappyEFGGHRI :53B:/D/1234567800570 :57A:RYWSSY2SXXX :59:/876521345678 XYSDEF :70:NOTES TO BANK :71A:ABC
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Jun 2016 07:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275884#M55231</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-08T07:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string from Swift messages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275903#M55238</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/27659"&gt;@angorwat﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length Acct_no $8
       BSB_no  $6;
input @':59:/' _nbr :$20. _txt :$10. _txt @;
_l=length(_nbr);
if _l&amp;gt;8 then do;
  Acct_no=substr(_nbr, _l-7);
  BSB_no=substr(_nbr, 1, _l-8);
end;
else do;
  Acct_no=_nbr;
  if _txt='BSB' then input BSB_no;
end;
drop _:;
cards;
:SND:ABCDSASIAXXX :RCV:MNOPIN2SAXXX :20:XY1543514245054 :23B:CRED :32A:12345AUD1073,23 :50K:/1234568 XYZ P.O.BOX 316 ABCD-31952 :52A:DEFGGHRI :53B:/D/1234567800570 :57A:REWSSY2SXXX :59:/12345678 XYSDEF BSB 7654 :70:NOTES TO BANK :71A:ABC
:SND:ABCDSASIAXXX :RCV:MNOPIN2SAXXX :20:XY1543514245054 :23B:CRED :32A:12345AUD1073,23 :50K:/1234568 XYZ P.O.BOX 316 ABCD-31952 :52A:DEFGGHRI :53B:/D/1234567800570 :57A:REWSSY2SXXX :59:/876521345678 XYSDEF :70:NOTES TO BANK :71A:ABC
:SND:ABCDSASIAXXX :RCV:MNOPIN2SAXXX :20:XY1543514245054 :23B:CRED :32A:12345AUD1073,23 :50K:/1234568 XYZ P.O.BOX 316 ABCD-31952 :52A:DEFGGHRI :53B:/D/1234567800570 :57A:REWSSY2SXXX :59:/21345678 XYSDEF :70:NOTES TO BANK :71A:ABC
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Edit: You may want to include additional checks and create log messages if unexpected values are encountered, e.g. &lt;FONT face="courier new,courier"&gt;_l&amp;gt;14&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;_l&amp;lt;8&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 08:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275903#M55238</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-06-08T08:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string from Swift messages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275966#M55259</link>
      <description>&lt;P&gt;I think your task is if not impossible, but at least very inefficient way of solving this.&lt;/P&gt;
&lt;P&gt;Your institution must in some place parse the Swift messages to be able to act on them.&lt;/P&gt;
&lt;P&gt;Besides the formal structure and rules of the Swift message&amp;nbsp;itself, your institution surely have some kind of algorithm to match account numbers.&lt;/P&gt;
&lt;P&gt;Account number can be erroneous, and probably altered manually by service staff. And I guess that you want to act on the valid account no that is actually used for the transaction.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, my advice is work out some kind of access to/extract from the database&amp;nbsp;that stores the pared messages.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 13:57:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-string-from-Swift-messages/m-p/275966#M55259</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-06-08T13:57:58Z</dc:date>
    </item>
  </channel>
</rss>

