<?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: XMLMAP with XPATH statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/XMLMAP-with-XPATH-statements/m-p/39244#M7942</link>
    <description>You bet;  if the file are really huge, it makes sense to throw the unwanted ones away right when you extract them from the XML...&lt;BR /&gt;
&lt;BR /&gt;
data work.person;&lt;BR /&gt;
set bryanmat.person;&lt;BR /&gt;
where question in ('FavoriteColor', 'FavoriteFood');&lt;BR /&gt;
run;</description>
    <pubDate>Wed, 13 Jan 2010 18:03:14 GMT</pubDate>
    <dc:creator>Paul_Kent_SAS</dc:creator>
    <dc:date>2010-01-13T18:03:14Z</dc:date>
    <item>
      <title>XMLMAP with XPATH statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/XMLMAP-with-XPATH-statements/m-p/39240#M7938</link>
      <description>I'm looking to transform some data where we have a group of question/answer sections for different options.    The basic format is as such:&lt;BR /&gt;
&lt;BR /&gt;
&lt;PERSON&gt;&lt;BR /&gt;
  &lt;ID&gt;123&lt;/ID&gt;&lt;BR /&gt;
  &lt;QA&gt;&lt;BR /&gt;
    &lt;QUESTION&gt;FavoriteColor&lt;/QUESTION&gt;&lt;BR /&gt;
    &lt;ANSWER&gt;blue&lt;/ANSWER&gt;&lt;BR /&gt;
  &lt;/QA&gt;&lt;BR /&gt;
  &lt;QA&gt;&lt;BR /&gt;
    &lt;QUESTION&gt;FavoriteFood&lt;/QUESTION&gt;&lt;BR /&gt;
    &lt;ANSWER&gt;pizza&lt;/ANSWER&gt;&lt;BR /&gt;
  &lt;/QA&gt;&lt;BR /&gt;
&lt;/PERSON&gt;&lt;BR /&gt;
&lt;BR /&gt;
There can be a large list of questions/answers but what I really want to do is setup a datasaet with id, FavoriteColor, and FavoriteFood variables.  Can I setup the path in an XML map which basically says something such as:&lt;BR /&gt;
&lt;BR /&gt;
person/qa[question='FavoriteFood']/answer&lt;BR /&gt;
person/qa[question='FavoriteColor']/answer&lt;BR /&gt;
&lt;BR /&gt;
Data should look like:&lt;BR /&gt;
&lt;BR /&gt;
ID       FavoriteFood     FavoriteColor&lt;BR /&gt;
123         pizza                    blue&lt;BR /&gt;
&lt;BR /&gt;
When I attempt something similar to this in the SAS XML mapper I get no value.  Is this even possible to do within a .map file?&lt;BR /&gt;
&lt;BR /&gt;
I could possibly transpose this via PROC TRANSPOSE, but I am really only interested in mapping a few key values.&lt;BR /&gt;
&lt;BR /&gt;
Thoughts or suggestions?</description>
      <pubDate>Mon, 11 Jan 2010 22:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/XMLMAP-with-XPATH-statements/m-p/39240#M7938</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-01-11T22:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: XMLMAP with XPATH statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/XMLMAP-with-XPATH-statements/m-p/39241#M7939</link>
      <description>try to move id line inside each qa. it works to define a library refer to the file under SAS 9.2 . then you may use proc transpose or other approach to get what you need.&lt;BR /&gt;
&lt;BR /&gt;
&lt;PERSON&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;QA&gt;&lt;BR /&gt;
&lt;ID&gt;123&lt;/ID&gt;&lt;BR /&gt;
&lt;QUESTION&gt;FavoriteColor&lt;/QUESTION&gt;&lt;BR /&gt;
&lt;ANSWER&gt;blue&lt;/ANSWER&gt;&lt;BR /&gt;
&lt;/QA&gt;&lt;BR /&gt;
&lt;QA&gt;&lt;BR /&gt;
&lt;ID&gt;123&lt;/ID&gt;&lt;BR /&gt;
&lt;QUESTION&gt;FavoriteFood&lt;/QUESTION&gt;&lt;BR /&gt;
&lt;ANSWER&gt;pizza&lt;/ANSWER&gt;&lt;BR /&gt;
&lt;/QA&gt;&lt;BR /&gt;
&lt;/PERSON&gt;&lt;BR /&gt;
&lt;BR /&gt;
libname test xml "yourxmlfile.xml";</description>
      <pubDate>Tue, 12 Jan 2010 17:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/XMLMAP-with-XPATH-statements/m-p/39241#M7939</guid>
      <dc:creator>SUN59338</dc:creator>
      <dc:date>2010-01-12T17:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: XMLMAP with XPATH statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/XMLMAP-with-XPATH-statements/m-p/39242#M7940</link>
      <description>sorry.  you cant use fancy xpath like you want to;   You dont have to re-arrange the XML however.&lt;BR /&gt;
&lt;BR /&gt;
i used the map/transpose technique you described.&lt;BR /&gt;
&lt;BR /&gt;
here is the xml i used for your data (i added a mystuff root node):&lt;BR /&gt;
&lt;BR /&gt;
&lt;MYSTUFF&gt;&lt;BR /&gt;
&lt;PERSON&gt;&lt;BR /&gt;
&lt;ID&gt;123&lt;/ID&gt;&lt;BR /&gt;
&lt;QA&gt;&lt;BR /&gt;
&lt;QUESTION&gt;FavoriteColor&lt;/QUESTION&gt;&lt;BR /&gt;
&lt;ANSWER&gt;blue&lt;/ANSWER&gt;&lt;BR /&gt;
&lt;/QA&gt;&lt;BR /&gt;
&lt;QA&gt;&lt;BR /&gt;
&lt;QUESTION&gt;FavoriteFood&lt;/QUESTION&gt;&lt;BR /&gt;
&lt;ANSWER&gt;pizza&lt;/ANSWER&gt;&lt;BR /&gt;
&lt;/QA&gt;&lt;BR /&gt;
&lt;/PERSON&gt;&lt;BR /&gt;
&lt;/MYSTUFF&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
here is my map:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;!-- ############################################################ --&gt;&lt;BR /&gt;
&lt;!-- 2010-01-12T19:49:28 --&gt;&lt;BR /&gt;
&lt;!-- SAS XML Libname Engine Map --&gt;&lt;BR /&gt;
&lt;!-- Generated by XML Mapper, 902000.3.6.20090116170000_v920 --&gt;&lt;BR /&gt;
&lt;!-- ############################################################ --&gt;&lt;BR /&gt;
&lt;SXLEMAP name="SXLEMAP" version="1.2"&gt;&lt;BR /&gt;
&lt;BR /&gt;
    &lt;!-- ############################################################ --&gt;&lt;BR /&gt;
    &lt;TABLE name="person"&gt;&lt;BR /&gt;
        &lt;TABLE-PATH syntax="XPath"&gt;/mystuff/person/qa&lt;/TABLE-PATH&gt;&lt;BR /&gt;
&lt;BR /&gt;
        &lt;COLUMN name="id" retain="YES"&gt;&lt;BR /&gt;
            &lt;PATH syntax="XPath"&gt;/mystuff/person/id&lt;/PATH&gt;&lt;BR /&gt;
            &lt;TYPE&gt;numeric&lt;/TYPE&gt;&lt;BR /&gt;
            &lt;DATATYPE&gt;integer&lt;/DATATYPE&gt;&lt;BR /&gt;
        &lt;/COLUMN&gt;&lt;BR /&gt;
&lt;BR /&gt;
        &lt;COLUMN name="question"&gt;&lt;BR /&gt;
            &lt;PATH syntax="XPath"&gt;/mystuff/person/qa/question&lt;/PATH&gt;&lt;BR /&gt;
            &lt;TYPE&gt;character&lt;/TYPE&gt;&lt;BR /&gt;
            &lt;DATATYPE&gt;string&lt;/DATATYPE&gt;&lt;BR /&gt;
            &lt;LENGTH&gt;13&lt;/LENGTH&gt;&lt;BR /&gt;
        &lt;/COLUMN&gt;&lt;BR /&gt;
&lt;BR /&gt;
        &lt;COLUMN name="answer"&gt;&lt;BR /&gt;
            &lt;PATH syntax="XPath"&gt;/mystuff/person/qa/answer&lt;/PATH&gt;&lt;BR /&gt;
            &lt;TYPE&gt;character&lt;/TYPE&gt;&lt;BR /&gt;
            &lt;DATATYPE&gt;string&lt;/DATATYPE&gt;&lt;BR /&gt;
            &lt;LENGTH&gt;5&lt;/LENGTH&gt;&lt;BR /&gt;
        &lt;/COLUMN&gt;&lt;BR /&gt;
&lt;BR /&gt;
    &lt;/TABLE&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;/SXLEMAP&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
and here is my sas job:&lt;BR /&gt;
filename  bryanmat 'C:\Paul\XML\bryanmat.xml';&lt;BR /&gt;
filename  SXLEMAP 'C:\Paul\XML\brianmat.map';&lt;BR /&gt;
libname   bryanmat xml92 xmlmap=SXLEMAP access=READONLY;&lt;BR /&gt;
&lt;BR /&gt;
data work.person; &lt;BR /&gt;
 set bryanmat.person;&lt;BR /&gt;
 run;&lt;BR /&gt;
 &lt;BR /&gt;
proc print;&lt;BR /&gt;
 title 'before transpose';&lt;BR /&gt;
 run;&lt;BR /&gt;
&lt;BR /&gt;
proc transpose data=person out=person; &lt;BR /&gt;
  by id;&lt;BR /&gt;
  id question;&lt;BR /&gt;
  var answer;&lt;BR /&gt;
  where question in ('FavoriteColor', 'FavoriteFood');&lt;BR /&gt;
  run;&lt;BR /&gt;
&lt;BR /&gt;
proc print;&lt;BR /&gt;
 title 'after transpose';&lt;BR /&gt;
 run;</description>
      <pubDate>Wed, 13 Jan 2010 00:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/XMLMAP-with-XPATH-statements/m-p/39242#M7940</guid>
      <dc:creator>Paul_Kent_SAS</dc:creator>
      <dc:date>2010-01-13T00:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: XMLMAP with XPATH statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/XMLMAP-with-XPATH-statements/m-p/39243#M7941</link>
      <description>Thanks Paul.  I was working on going the PROC TRANSPOSE route but I didn't think of using it with a where clause.  I think that helped to solve the missing piece of the puzzle.</description>
      <pubDate>Wed, 13 Jan 2010 15:12:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/XMLMAP-with-XPATH-statements/m-p/39243#M7941</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-01-13T15:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: XMLMAP with XPATH statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/XMLMAP-with-XPATH-statements/m-p/39244#M7942</link>
      <description>You bet;  if the file are really huge, it makes sense to throw the unwanted ones away right when you extract them from the XML...&lt;BR /&gt;
&lt;BR /&gt;
data work.person;&lt;BR /&gt;
set bryanmat.person;&lt;BR /&gt;
where question in ('FavoriteColor', 'FavoriteFood');&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 13 Jan 2010 18:03:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/XMLMAP-with-XPATH-statements/m-p/39244#M7942</guid>
      <dc:creator>Paul_Kent_SAS</dc:creator>
      <dc:date>2010-01-13T18:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: XMLMAP with XPATH statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/XMLMAP-with-XPATH-statements/m-p/39245#M7943</link>
      <description>Oops.  Sorry about the bryan/brian mix up.  Daughters beau is a bryan and my tired fingers musta been on automatic &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
      <pubDate>Wed, 13 Jan 2010 18:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/XMLMAP-with-XPATH-statements/m-p/39245#M7943</guid>
      <dc:creator>Paul_Kent_SAS</dc:creator>
      <dc:date>2010-01-13T18:41:03Z</dc:date>
    </item>
  </channel>
</rss>

