<?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: Import an XML file - complex structure in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406466#M98973</link>
    <description>&lt;P&gt;Since the link may disappear at some point, I am uploading it here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, this works with any XML: it is not specific to your source. It may not be exactly what is needed so let me know of any issues.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Oct 2017 11:52:28 GMT</pubDate>
    <dc:creator>AlanC</dc:creator>
    <dc:date>2017-10-23T11:52:28Z</dc:date>
    <item>
      <title>Import an XML file - complex structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406065#M98821</link>
      <description>&lt;P&gt;I've tried the XML Map (XMLV2) but sadly don't have the XML mapper installed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I've tried:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename sample "OPEN_DATA_1.xml";
filename mapfile "test.map";
libname sample xmlv2 xmlmap=mapfile automap=replace;

proc copy in=sample out=work;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1200 filename sample "OPEN_DATA_1.xml";&lt;BR /&gt;1201 filename mapfile "test.map";&lt;BR /&gt;1202 libname sample xmlv2 xmlmap=mapfile automap=replace;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;ERROR: The creation of the XML Mapper file failed.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;ERROR: Error in the LIBNAME statement.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;1203&lt;BR /&gt;1204 proc copy in=sample out=work;&lt;BR /&gt;1205 run;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;ERROR: Libref SAMPLE is not assigned.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;NOTE: Statements not processed because of errors noted above.&lt;BR /&gt;NOTE: PROCEDURE COPY used (Total process time):&lt;BR /&gt; real time 0.01 seconds&lt;BR /&gt; cpu time 0.01 seconds&lt;/P&gt;
&lt;P&gt;NOTE: Parsing with high validation.&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;ERROR: Unable to parse the specified file:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt; file:OPEN_DATA_1.xml&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt; &lt;FONT color="#FF0000"&gt;Exception class: java.lang.OutOfMemoryError&lt;/FONT&gt;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of&lt;BR /&gt; errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be very much appreciated in reading this file. I've attached the file as well but it can be downloaded from here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://open.canada.ca/data/en/dataset/0032ce54-c5dd-4b66-99a0-320a7b5e99f2" target="_blank"&gt;http://open.canada.ca/data/en/dataset/0032ce54-c5dd-4b66-99a0-320a7b5e99f2&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd be fine with scraping the API as well, which returns JSON.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sadly I'm on SAS 9.4M3 which doesn't have the JSON lib yet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Note that I've changed the extension from XML to TXT and zipped it to allow for the upload to occur.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 18:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406065#M98821</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T18:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Import an XML file - complex structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406227#M98869</link>
      <description>&lt;P&gt;After a week (years really) of bloody battle with the XML libname, i am bailing with trying to get it to read/write complex XML.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest using an alternate tool for the XML/JSON such as C# (my choice)/PowerShell/Python. Spend time getting the data formed then bring it into SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your alternate is to&amp;nbsp;parse it. Poor alternative when there are engines that can handle it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Oct 2017 11:43:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406227#M98869</guid>
      <dc:creator>AlanC</dc:creator>
      <dc:date>2017-10-21T11:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Import an XML file - complex structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406236#M98870</link>
      <description>&lt;PRE&gt;
Could you use SAS XML Mapper to get the xml map and import it again ?


&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Oct 2017 13:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406236#M98870</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-21T13:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Import an XML file - complex structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406239#M98871</link>
      <description>&lt;PRE&gt;
Could post it as JSON file. Maybe I could write some data step code to get it.

And also you can use SAS University Edition to parse JSON .

&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Oct 2017 13:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406239#M98871</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-21T13:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Import an XML file - complex structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406265#M98882</link>
      <description>Keep in mind also, the XML Mapper is a free download from SAS. I am not even sure SAS is required on the machine.</description>
      <pubDate>Sat, 21 Oct 2017 16:28:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406265#M98882</guid>
      <dc:creator>AlanC</dc:creator>
      <dc:date>2017-10-21T16:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: Import an XML file - complex structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406267#M98884</link>
      <description>&lt;P&gt;I can't use SAS UE because it's for work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13798"&gt;@AlanC&lt;/a&gt;&amp;nbsp;I did parse it manually, it took two hours AFTER I spend about 4 fighting with R/SAS and getting this file in...I think I'll try Python instead now. I still want it automated because I have to read about 39 of these every week....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;The JSON is via an API, here's the call:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://www.ic.gc.ca/app/scr/cc/CorporationsCanada/api/corporations/1007.json?lang=eng" target="_blank"&gt;https://www.ic.gc.ca/app/scr/cc/CorporationsCanada/api/corporations/1007.json?lang=eng&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It will return a JSON file.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Oct 2017 16:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406267#M98884</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-21T16:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Import an XML file - complex structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406268#M98885</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13798"&gt;@AlanC&lt;/a&gt;&amp;nbsp;No install privileges on these machines. I'll give it a shot though, thanks for the suggestion!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Oct 2017 16:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406268#M98885</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-21T16:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Import an XML file - complex structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406272#M98888</link>
      <description>What O/S is your laptop? I can make a run at it later this weekend (flying today) but would prefer c# to do it. I can make an exercise standalone but maintenance would be on you&lt;BR /&gt;</description>
      <pubDate>Sat, 21 Oct 2017 16:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406272#M98888</guid>
      <dc:creator>AlanC</dc:creator>
      <dc:date>2017-10-21T16:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Import an XML file - complex structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406340#M98925</link>
      <description>&lt;P&gt;Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wrote a C# program that parses all of these XML files and turns them into tab-delimited files with separate files per XML file. I have zipped it up and put it here. Be patient if you run it because the XML is very layered so the parse takes time:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://1drv.ms/u/s!Ajc9gcr7VcqLo68J3nueWo-b81vQlg" target="_blank"&gt;https://1drv.ms/u/s!Ajc9gcr7VcqLo68J3nueWo-b81vQlg&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The exe takes 2 args at the command-line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The source directory where the XML is located and the ouput location for the unwound files. here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"X:\temp\XMLTest" "x:\temp\XMLTest\Out"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will find the exe in the bin directory under debug.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To provide a sense, it took me around 20 mins to code this. I would suggest if you want further control, you load the data into an XDocument and then XPath what you need out. I am happy to help you do the coding if desired. I will be onsite this week so will have limited time but will respond in the evening if this is the direction you wish to go. Personally, I would suggest writing these to a SQL Express database instead of delimited but delimited illustrates the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck. If you need help on the JSON side, ping me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alan&lt;/P&gt;</description>
      <pubDate>Sun, 22 Oct 2017 03:47:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406340#M98925</guid>
      <dc:creator>AlanC</dc:creator>
      <dc:date>2017-10-22T03:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: Import an XML file - complex structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406402#M98951</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13798"&gt;@AlanC&lt;/a&gt;&amp;nbsp;wow! Thanks, so much! I'll have to look at this tomorrow and see what I can run on my desktop, looking forward to it and appreciate your help a ton!&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 00:39:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406402#M98951</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-23T00:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: Import an XML file - complex structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406466#M98973</link>
      <description>&lt;P&gt;Since the link may disappear at some point, I am uploading it here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, this works with any XML: it is not specific to your source. It may not be exactly what is needed so let me know of any issues.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 11:52:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-an-XML-file-complex-structure/m-p/406466#M98973</guid>
      <dc:creator>AlanC</dc:creator>
      <dc:date>2017-10-23T11:52:28Z</dc:date>
    </item>
  </channel>
</rss>

