BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

Is there any way to create a SAS code to produce a dataset from the following XML?

 

<?xml version="1.0" encoding="iso-8859-1" ?>
<NHL>
  <CONFERENCE> Eastern 
    <DIVISION> Southeast  
      <TEAM name="Thrashers"  abbrev="ATL" />  
   </DIVISION>
 </CONFERENCE> 
</NHL>
13 REPLIES 13
Reeza
Super User

@Babloo wrote:

Is there any way to create a SAS code to produce a dataset from the following XML?

 

<?xml version="1.0" encoding="iso-8859-1" ?>
<NHL>
  <CONFERENCE> Eastern 
    <DIVISION> Southeast  
      <TEAM name="Thrashers"  abbrev="ATL" />  
   </DIVISION>
 </CONFERENCE> 
</NHL>

Yes, XML Mapper or XML libname. Or you can always parse it manually...sometimes that ends up being the fastest solution. 

Babloo
Rhodochrosite | Level 12
Is there any way that you can help me create the SAS code for the above
example?
Reeza
Super User

Same as every other question, show what you have, what you expect as output and what you've tried and you'll get help. 

 

 

Cynthia_sas
SAS Super FREQ
Hi:
What code have you tried? For example, this Tech Support note seems to have an example of reading the NHL xml file using an XML Map: http://support.sas.com/documentation/cdl/en/engxml/62845/HTML/default/viewer.htm#a002484891.htm
cynthia
gamotte
Rhodochrosite | Level 12

Hello,

 

Try the following SAS code :

filename xmldata "c:\temp\test XML SAS\test.xml";
filename xmlmap  "c:\temp\test XML SAS\mapping.map";
libname  xmldata xml xmlmap=xmlmap;


data test;
set xmldata.mytable;
run;

With test.xml the XML file you described and mapping.map as follows

<SXLEMAP version="1.2" name="SXLEMAP">
    <TABLE name="mytable">
        <TABLE-PATH syntax="XPATH">
           /NHL/CONFERENCE/DIVISION/TEAM
         </TABLE-PATH>
        <COLUMN name="Conference">
            <PATH syntax="XPath">/NHL/CONFERENCE</PATH>
            <TYPE>character</TYPE>
            <DATATYPE>string</DATATYPE>
            <LENGTH>10</LENGTH>
        </COLUMN>
        <COLUMN name="Division">
            <PATH syntax="XPath">/NHL/CONFERENCE/DIVISION</PATH>
            <TYPE>character</TYPE>
            <DATATYPE>string</DATATYPE>
            <LENGTH>10</LENGTH>
        </COLUMN>
        <COLUMN name="Team">
            <PATH syntax="XPath">/NHL/CONFERENCE/DIVISION/TEAM@name</PATH>
            <TYPE>character</TYPE>
            <DATATYPE>string</DATATYPE>
            <LENGTH>10</LENGTH>
        </COLUMN>
        <COLUMN name="Abbreviation">
            <PATH syntax="XPath">/NHL/CONFERENCE/DIVISION/TEAM@abbrev</PATH>
            <TYPE>character</TYPE>
            <DATATYPE>string</DATATYPE>
            <LENGTH>10</LENGTH>
        </COLUMN>
    </TABLE>
</SXLEMAP>
Babloo
Rhodochrosite | Level 12

Received the following error. Could you please guide me to resolve the issue?

 

24         data test;
25         set xmldata.mytable;
ERROR: Physical file does not exist, /wrk1/mapping.map.
       encountered during XMLMap parsing
       occurred at or near line 1, column 1
ERROR: XML describe error: Internal processing error.
26         run;
gamotte
Rhodochrosite | Level 12

Hello,

 

It is written in the log :

 

ERROR: Physical file does not exist, /wrk1/mapping.map

Check that the path to your map file is correct.

Babloo
Rhodochrosite | Level 12
Path is correct.But I don't have that .Map file in that folder.
gamotte
Rhodochrosite | Level 12

You have to create it there with the contents i provided in my first answer.

Babloo
Rhodochrosite | Level 12

Is there any way to format a XML file which has repetitive elements?

Babloo
Rhodochrosite | Level 12

Can we also create the mapping.map via SAS XML mapper?

gamotte
Rhodochrosite | Level 12

Yes, you can use XML mapper to create the map file as suggested by @Reeza.

maggiem_sas
SAS Employee

Here is the most recent version of the XML engine book, opened at the topics that discuss the XML Mapper: Using SAS XML Mapper to Generate and Update an XMLMap.

 

See also two videos about XMLMaps listed under "Videos" at http://support.sas.com/documentation/onlinedoc/base/index.html

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 2286 views
  • 3 likes
  • 5 in conversation