<?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: How to Read XML with .txt extention in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395622#M278035</link>
    <description>&lt;P&gt;Can you please post, a text file that includes exactly what you have, mabye 10 records? You can mask any fields that are needed and then post the remaining content. It really helps to have the actual file to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS can process XML files and this is XML.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What version of SAS do you have, the XML libraries are relatively new.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Sep 2017 16:39:22 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-09-13T16:39:22Z</dc:date>
    <item>
      <title>How to Read XML with .txt extension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395552#M278028</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was told the dataset is an ASCII text file and it is a composite of XML records. I am confused about it. It's not like XML file and I failed to read by:&lt;/P&gt;&lt;P&gt;proc import datafile = 'data.txt'&amp;nbsp;out=mydata dbms=dlm replace;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first two lines:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;personExport&amp;gt;&amp;lt;personId&amp;gt;123456&amp;lt;/personId&amp;gt;&amp;lt;Id&amp;gt;123456&amp;lt;/Id&amp;gt;&amp;lt;XmlRecord&amp;gt;&amp;lt;entityObject&amp;gt; &amp;lt;person eprsId="123456" eprsVersion="0" moduleId="109"&amp;gt; &amp;lt;addresses&amp;gt; &amp;lt;address locale="9e" type="yzN5D"&amp;gt; &amp;lt;stAddr1&amp;gt;4@Qd!qa4NW2@0-Eoe425&amp;lt;/stAddr1&amp;gt; &amp;lt;stAddr2&amp;gt;au@Uk&amp;lt;/stAddr2&amp;gt; &amp;lt;city&amp;gt;aZ?7zjWH?p&amp;lt;/city&amp;gt; &amp;lt;state&amp;gt;nb&amp;lt;/state&amp;gt; &amp;lt;postalCode&amp;gt;7LA@8SQd?e&amp;lt;/postalCode&amp;gt; &amp;lt;country&amp;gt;pTWWihi-xs&amp;lt;/country&amp;gt; &amp;lt;/address&amp;gt; &amp;lt;/addresses&amp;gt; &amp;lt;disabilityCodes&amp;gt; &amp;lt;disabilityCode&amp;gt;466&amp;lt;/disabilityCode&amp;gt; &amp;lt;disabilityCode&amp;gt;802&amp;lt;/disabilityCode&amp;gt; &amp;lt;/disabilityCodes&amp;gt; &amp;lt;name&amp;gt; &amp;lt;family&amp;gt;iNCkfiONdU&amp;lt;/family&amp;gt; &amp;lt;given&amp;gt;4-rOv9gdtG&amp;lt;/given&amp;gt; &amp;lt;middle&amp;gt;e&amp;lt;/middle&amp;gt; &amp;nbsp;&amp;lt;suffix&amp;gt;95XRA2id@t&amp;lt;/suffix&amp;gt; &amp;lt;/name&amp;gt; &amp;lt;message&amp;gt;None&amp;lt;/message&amp;gt; &amp;lt;/person&amp;gt;&amp;lt;/entityObject&amp;gt;&amp;lt;/XmlRecord&amp;gt;&amp;lt;/personExport&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;encounterExport&amp;gt;&amp;lt;encounterId&amp;gt;abcdefg123&amp;lt;/encounterId&amp;gt;&amp;lt;personId&amp;gt;123456&amp;lt;/personId&amp;gt;&amp;lt;Id&amp;gt;&lt;SPAN&gt;abcdefg123&lt;/SPAN&gt;&amp;lt;/Id&amp;gt;&amp;lt;XmlRecord&amp;gt;&amp;lt;entityObject personURI="/11777/person/d434b5bf.xml"&amp;gt; &amp;lt;encounter eprsId="&lt;SPAN&gt;abcdefg123&lt;/SPAN&gt;"&amp;nbsp; eprsVersion="0" moduleId="109" personId="d434b5bf"&amp;gt;&amp;nbsp;&amp;lt;admission&amp;gt; &amp;lt;admitDate&amp;gt;2020-12-05T14:25:11.2277943-07:00&amp;lt;/admitDate&amp;gt;&amp;nbsp;&amp;nbsp; &amp;lt;referralSourceCode&amp;gt;77270&amp;lt;/referralSourceCode&amp;gt;&amp;nbsp; &amp;lt;/admission&amp;gt;&amp;nbsp;&amp;lt;/encounter&amp;gt;&amp;lt;/entityObject&amp;gt;&amp;lt;/XmlRecord&amp;gt;&amp;lt;PersonId&amp;gt;123456&amp;lt;/PersonId&amp;gt;&amp;lt;/encounterExport&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I know it's hierarchical and each line begins with &amp;lt;personExport&amp;gt; or &amp;lt;encounterExport&amp;gt; or others. Also, the personId are same. I don't have XML map either.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure SAS can read it or not. It is not XML file, but it has XML records.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any thoughts will be appreciated!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 16:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395552#M278028</guid>
      <dc:creator>wy110</dc:creator>
      <dc:date>2017-09-13T16:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read XML with .txt extention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395568#M278029</link>
      <description>&lt;P&gt;It's an XML file, the extension doesn't really matter, they're all text files anyways the extension tells you what's inside (csv, json, xml, html).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at the libname XML.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings12/253-2012.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings12/253-2012.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 15:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395568#M278029</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-13T15:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read XML with .txt extention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395589#M278030</link>
      <description>&lt;P&gt;Thanks for your quick reply!&lt;/P&gt;&lt;P&gt;I read this paper and tried the programs before, there are errors:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;17136  data dat.data;
17137   set myxml.data;
ERROR: Expected a comment or processing instruction.
ERROR: Encountered during XMLMap parsing at or near line 2, column 1.
ERROR: XML describe error: Internal processing error.
17138  run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My most concern is, the text file doesn't have:&lt;/P&gt;&lt;P&gt;&lt;!-- ?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;windows-1252&amp;quot; ? --&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;?xml version="1.0" encoding="windows-1252" ?&amp;gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore I didn't consider it as XML file. Please correct me if I were wrong. Thanks!&lt;/P&gt;&lt;P&gt;&lt;!-- ?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;windows-1252&amp;quot; ? --&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 15:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395589#M278030</guid>
      <dc:creator>wy110</dc:creator>
      <dc:date>2017-09-13T15:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read XML with .txt extention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395603#M278031</link>
      <description>&lt;P&gt;Where are the libname statements?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 16:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395603#M278031</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-13T16:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read XML with .txt extension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395609#M278032</link>
      <description>&lt;P&gt;I can't say whether&amp;nbsp;it is an XML file (or not). It may have&amp;nbsp;records which contain XML, not the same as an XML file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does the file have an XML identifier as the very first line in the file? Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;?xml version="1.0" encoding="utf-16"?&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It also must have a single grouping element at the top.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you send us the top 10 lines in the file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 16:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395609#M278032</guid>
      <dc:creator>AlanC</dc:creator>
      <dc:date>2017-09-13T16:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read XML with .txt extension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395616#M278033</link>
      <description>&lt;P&gt;No, it does not have something like:&amp;nbsp;&lt;SPAN&gt;&amp;lt;?xml version="1.0" encoding="utf-16"?&amp;gt; This is one of my concerns as well.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The first two lines I have already posted, that's what I have. &amp;nbsp;I just truncated some details and I didn't change the structure of the data.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am not sure if the file can be imported by SAS. If not, it's fine, I just need to make sure that.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 16:33:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395616#M278033</guid>
      <dc:creator>wy110</dc:creator>
      <dc:date>2017-09-13T16:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read XML with .txt extention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395621#M278034</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname myxml xml 'Z:\data.txt';
LIBNAME DAT "C:\mylibrary";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;There are no issues with libname. Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 16:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395621#M278034</guid>
      <dc:creator>wy110</dc:creator>
      <dc:date>2017-09-13T16:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read XML with .txt extention</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395622#M278035</link>
      <description>&lt;P&gt;Can you please post, a text file that includes exactly what you have, mabye 10 records? You can mask any fields that are needed and then post the remaining content. It really helps to have the actual file to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS can process XML files and this is XML.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What version of SAS do you have, the XML libraries are relatively new.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 16:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395622#M278035</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-13T16:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read XML with .txt extension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395623#M278036</link>
      <description>&lt;P&gt;Ok, it is not an XML file then, simple enough. It is a collection of XML snippets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I normally would use C# and transform it since it can handle the way that this is structured. However, in the SAS world, some suggestions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. See if you can append the XML identifier to the top and include a wrapping element such as &amp;lt;Records&amp;gt; at the top and close it out at the bottom. That would make it a 'valid' XML file. Still doesn't solve your issue but gets it so you can read it into SAS easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Rip it using a data step. Ignore the fact that it is XML wrapped records and just use regex to parse it out. Read a record, parse it, output to dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a format I have seen before but I take it elsewhere to handle. If you want to keep it in a SAS world 100%, you probably have to unwind it yourself.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 16:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395623#M278036</guid>
      <dc:creator>AlanC</dc:creator>
      <dc:date>2017-09-13T16:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read XML with .txt extension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395861#M278037</link>
      <description>&lt;P&gt;To read XML you can rename the file and open in browser. These XML tools may help to read and beautify XML.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;A href="https://jsonformatter.org/xml-formatter" target="_blank"&gt;https://jsonformatter.org/xml-formatter&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://codebeautify.org/xmlviewer&amp;nbsp;" target="_blank"&gt;https://codebeautify.org/xmlviewer&amp;nbsp;&lt;/A&gt;&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Thu, 14 Sep 2017 08:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395861#M278037</guid>
      <dc:creator>jamesmalvi</dc:creator>
      <dc:date>2017-09-14T08:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read XML with .txt extension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395873#M278038</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/156667"&gt;@wy110&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Looks to me like XML formatted messages or something in this area.&lt;/P&gt;
&lt;P&gt;The XML structures in your two examples are not as simple as you believe. That's not a simple table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below sample code which reads the first of your message. The result are 9 tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will have to run this message by message and without the XSD it's going to take a bit to bring the data together.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file tmp;
  infile datalines truncover;
  input;
  put _infile_;
  datalines;
&amp;lt;personExport&amp;gt;
  &amp;lt;personId&amp;gt;123456&amp;lt;/personId&amp;gt;
  &amp;lt;Id&amp;gt;123456&amp;lt;/Id&amp;gt;
  &amp;lt;XmlRecord&amp;gt;
    &amp;lt;entityObject&amp;gt; 
      &amp;lt;person eprsId="123456" eprsVersion="0" moduleId="109"&amp;gt; 
        &amp;lt;addresses&amp;gt; 
          &amp;lt;address locale="9e" type="yzN5D"&amp;gt; 
            &amp;lt;stAddr1&amp;gt;4@Qd!qa4NW2@0-Eoe425&amp;lt;/stAddr1&amp;gt; 
            &amp;lt;stAddr2&amp;gt;au@Uk&amp;lt;/stAddr2&amp;gt; 
            &amp;lt;city&amp;gt;aZ?7zjWH?p&amp;lt;/city&amp;gt; 
            &amp;lt;state&amp;gt;nb&amp;lt;/state&amp;gt; 
            &amp;lt;postalCode&amp;gt;7LA@8SQd?e&amp;lt;/postalCode&amp;gt; 
            &amp;lt;country&amp;gt;pTWWihi-xs&amp;lt;/country&amp;gt; 
          &amp;lt;/address&amp;gt; 
        &amp;lt;/addresses&amp;gt; 
        &amp;lt;disabilityCodes&amp;gt; 
          &amp;lt;disabilityCode&amp;gt;466&amp;lt;/disabilityCode&amp;gt; 
          &amp;lt;disabilityCode&amp;gt;802&amp;lt;/disabilityCode&amp;gt; 
        &amp;lt;/disabilityCodes&amp;gt; 
        &amp;lt;name&amp;gt; 
          &amp;lt;family&amp;gt;iNCkfiONdU&amp;lt;/family&amp;gt; 
          &amp;lt;given&amp;gt;4-rOv9gdtG&amp;lt;/given&amp;gt; 
          &amp;lt;middle&amp;gt;e&amp;lt;/middle&amp;gt;  
          &amp;lt;suffix&amp;gt;95XRA2id@t&amp;lt;/suffix&amp;gt; 
        &amp;lt;/name&amp;gt; 
        &amp;lt;message&amp;gt;None&amp;lt;/message&amp;gt; 
      &amp;lt;/person&amp;gt;
    &amp;lt;/entityObject&amp;gt;
  &amp;lt;/XmlRecord&amp;gt;
&amp;lt;/personExport&amp;gt;
;
run;

filename map temp;
libname test xmlv2 "%sysfunc(pathname(tmp))" automap=replace xmlmap="%sysfunc(pathname(map))";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 139px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15138i9C80F4FA838FB809/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 10:23:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-XML-with-txt-extension/m-p/395873#M278038</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-14T10:23:08Z</dc:date>
    </item>
  </channel>
</rss>

