<?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: extracting data from text field which contains xml in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/extracting-data-from-text-field-which-contains-xml/m-p/663414#M198033</link>
    <description>great it worked, thank you very much s_lassen&lt;BR /&gt;</description>
    <pubDate>Fri, 19 Jun 2020 09:43:33 GMT</pubDate>
    <dc:creator>veerand</dc:creator>
    <dc:date>2020-06-19T09:43:33Z</dc:date>
    <item>
      <title>extracting data from text field which contains xml</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extracting-data-from-text-field-which-contains-xml/m-p/663405#M198028</link>
      <description>&lt;P&gt;I work with SAS Data Integration Studio and need extract multiple addresses from text field which contains xml. For security reasons my SAS enviroment is quite closed, I cant use PIPE or FINDNTH(). I dont have access to original XML file aswell.&lt;BR /&gt;So far I managed with simple functions as SUBSTR and INDEX to shorten original text field and managed to get first address from textfield but as there more addresses I cant find solution for extracting second or sixth or n-th addresses.&amp;nbsp;&lt;BR /&gt;My table looks like and&amp;nbsp;count is how many strings &amp;lt;movementOfGoods&amp;gt; are in text field as how many rows I need for ID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="veerand_0-1592554119300.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/46379i2502A56504FBD193/image-size/medium?v=v2&amp;amp;px=400" role="button" title="veerand_0-1592554119300.png" alt="veerand_0-1592554119300.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;XML field contains:&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;movementOfGoods&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;qualifierOfTheIdentification&amp;gt;Z&amp;lt;/qualifierOfTheIdentification&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;legalBaseCode&amp;gt;A&amp;lt;/legalBaseCode&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;holderEORINumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;eORINumber&amp;gt;EEReplacedCodeForSecurityReasons&amp;lt;/eORINumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/holderEORINumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;country&amp;gt;EE&amp;lt;/country&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;typeOfLocationCode&amp;gt;B&amp;lt;/typeOfLocationCode&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;freeTextDescription&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;name&amp;gt;ReplacedCodeForSecurityReasons/001&amp;lt;/name&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;streetAndNumber&amp;gt;Tähe tn 106a&amp;lt;/streetAndNumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;postcode&amp;gt;50107&amp;lt;/postcode&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;city&amp;gt;Tartu&amp;lt;/city&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;country&amp;gt;EE&amp;lt;/country&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/freeTextDescription&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/movementOfGoods&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;movementOfGoods&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;qualifierOfTheIdentification&amp;gt;Z&amp;lt;/qualifierOfTheIdentification&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;legalBaseCode&amp;gt;A&amp;lt;/legalBaseCode&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;holderEORINumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;eORINumber&amp;gt;EEReplacedCodeForSecurityReasons&amp;lt;/eORINumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/holderEORINumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;country&amp;gt;EE&amp;lt;/country&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;typeOfLocationCode&amp;gt;B&amp;lt;/typeOfLocationCode&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;freeTextDescription&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;name&amp;gt;ReplacedCodeForSecurityReasons/007&amp;lt;/name&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;streetAndNumber&amp;gt;Jaama pst 26&amp;lt;/streetAndNumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;postcode&amp;gt;44311&amp;lt;/postcode&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;city&amp;gt;Rakvere&amp;lt;/city&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;country&amp;gt;EE&amp;lt;/country&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/freeTextDescription&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/movementOfGoods&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;movementOfGoods&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;qualifierOfTheIdentification&amp;gt;Z&amp;lt;/qualifierOfTheIdentification&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;legalBaseCode&amp;gt;A&amp;lt;/legalBaseCode&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;holderEORINumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;eORINumber&amp;gt;EEReplacedCodeForSecurityReasons&amp;lt;/eORINumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/holderEORINumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;country&amp;gt;EE&amp;lt;/country&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;typeOfLocationCode&amp;gt;B&amp;lt;/typeOfLocationCode&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;freeTextDescription&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;name&amp;gt;ReplacedCodeForSecurityReasons/008&amp;lt;/name&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;streetAndNumber&amp;gt;Linnase tn 6&amp;lt;/streetAndNumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;postcode&amp;gt;44208&amp;lt;/postcode&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;city&amp;gt;Rakvere vald, Aluvere&amp;lt;/city&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;country&amp;gt;EE&amp;lt;/country&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/freeTextDescription&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/movementOfGoods&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;movementOfGoods&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;qualifierOfTheIdentification&amp;gt;Z&amp;lt;/qualifierOfTheIdentification&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;legalBaseCode&amp;gt;A&amp;lt;/legalBaseCode&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;holderEORINumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;eORINumber&amp;gt;EEReplacedCodeForSecurityReasons&amp;lt;/eORINumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/holderEORINumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;country&amp;gt;EE&amp;lt;/country&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;typeOfLocationCode&amp;gt;B&amp;lt;/typeOfLocationCode&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;freeTextDescription&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;name&amp;gt;ReplacedCodeForSecurityReasons/010&amp;lt;/name&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;streetAndNumber&amp;gt;Kooli tn 10&amp;lt;/streetAndNumber&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;postcode&amp;gt;76102&amp;lt;/postcode&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;city&amp;gt;Rummu, Harjumaa&amp;lt;/city&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;country&amp;gt;EE&amp;lt;/country&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/freeTextDescription&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/movementOfGoods&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/temporaryStorageCustomsDecisionInformation&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/decisionRelatedInformation&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;customsDecisionStatus&amp;gt;01&amp;lt;/customsDecisionStatus&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;customsDecisionStatusDate&amp;gt;2019-12-04&amp;lt;/customsDecisionStatusDate&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;publicationAgreement&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;agreementForPublication&amp;gt;1&amp;lt;/agreementForPublication&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/publicationAgreement&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/customsDecisionAuthorisationData&amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the end I need table which look like&lt;/P&gt;&lt;P&gt;QUALIFICATION_IDENTIFICATION streetAndNumber,city as address&lt;BR /&gt;EETSTEE1000EE-2019-INR53390 Tähe tn 106a, Tartu&lt;BR /&gt;EETSTEE1000EE-2019-INR53390 Jaama pst 26, Rakvere&lt;BR /&gt;EETSTEE1000EE-2019-INR53390 Linnase tn 6, Rakvere vald, Aluvere&lt;BR /&gt;EETSTEE1000EE-2019-INR53390 Kooli tn 10, Rummu, Harjumaa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me out&lt;/P&gt;&lt;P&gt;Andres Veer&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 08:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extracting-data-from-text-field-which-contains-xml/m-p/663405#M198028</guid>
      <dc:creator>veerand</dc:creator>
      <dc:date>2020-06-19T08:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: extracting data from text field which contains xml</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extracting-data-from-text-field-which-contains-xml/m-p/663408#M198030</link>
      <description>&lt;P&gt;Please try the below code , I assumed that the xml data is in a txt file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename sam '~/sample.txt';

proc import datafile=sam out=sample dbms=tab replace;
getnames=no;
run;

data want;
set sample;
retain streetAndNumber;
if prxmatch('m/streetAndNumber/oi',var1)&amp;gt;0 then streetAndNumber=prxchange('s/(.*&amp;gt;)(.*)(&amp;lt;.*)/$2/oi',-1,var1);
if prxmatch('m/city/oi',var1)&amp;gt;0 then cityasaddress=prxchange('s/(.*&amp;gt;)(.*)(&amp;lt;.*)/$2/oi',-1,var1);
QUALIFICATION_IDENTIFICATION='EETSTEE1000EE-2019-INR53390';
if cityasaddress ne '';
drop var1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jun 2020 08:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extracting-data-from-text-field-which-contains-xml/m-p/663408#M198030</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-06-19T08:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: extracting data from text field which contains xml</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extracting-data-from-text-field-which-contains-xml/m-p/663409#M198031</link>
      <description>tx I'll try, but xml data is in sas table field not as txt file</description>
      <pubDate>Fri, 19 Jun 2020 09:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extracting-data-from-text-field-which-contains-xml/m-p/663409#M198031</guid>
      <dc:creator>veerand</dc:creator>
      <dc:date>2020-06-19T09:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: extracting data from text field which contains xml</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extracting-data-from-text-field-which-contains-xml/m-p/663413#M198032</link>
      <description>&lt;P&gt;Here is a way to do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length streetAndNumber city $200;
  pos=1;
  do until(0);
    pos=find(XML,'&amp;lt;movementOfGoods&amp;gt;',pos);
    if pos=0 then leave;
    streetAndNumber=scan(substr(XML,find(XML,'&amp;lt;streetAndNumber&amp;gt;',pos)),2,'&amp;gt;&amp;lt;');
    city=scan(substr(XML,find(XML,'&amp;lt;city&amp;gt;',pos)),2,'&amp;gt;&amp;lt;');
    output;
    pos=find(XML,'&amp;lt;/movementOfGoods&amp;gt;',pos);
    end;
  keep &lt;SPAN&gt;QUALIFICATION_IDENTIFICATION&amp;nbsp;&lt;/SPAN&gt;streetAndNumber city;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jun 2020 09:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extracting-data-from-text-field-which-contains-xml/m-p/663413#M198032</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-06-19T09:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: extracting data from text field which contains xml</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extracting-data-from-text-field-which-contains-xml/m-p/663414#M198033</link>
      <description>great it worked, thank you very much s_lassen&lt;BR /&gt;</description>
      <pubDate>Fri, 19 Jun 2020 09:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extracting-data-from-text-field-which-contains-xml/m-p/663414#M198033</guid>
      <dc:creator>veerand</dc:creator>
      <dc:date>2020-06-19T09:43:33Z</dc:date>
    </item>
  </channel>
</rss>

