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>
@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.
Same as every other question, show what you have, what you expect as output and what you've tried and you'll get help.
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>
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;
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.
You have to create it there with the contents i provided in my first answer.
Is there any way to format a XML file which has repetitive elements?
Can we also create the mapping.map via SAS XML mapper?
Yes, you can use XML mapper to create the map file as suggested by @Reeza.
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.