Post by AldiHi,
I am trying to read some doc in xml using sas v9.1 for win, os=xp.
ods xml file = 'c:\aldi2\xml\exercise5.xml'; run;
proc means data = sashelp.air;
var air;
run;
ods xml close; run;
libname trans xml 'c:\aldi2\xml\exercise5.xml';
proc print data=trans.exercise5;
title "ex5";
run;
Why sas is saying that the data does not exist?
Hi, Aldi,
Nice try, but it seems that there still are some learning curve left ahead
of you. The ods xml destination produces an xml document that is similar
to what markup type=events_map destination produces. The resulting xml
document has all the details about events proc means generates. If you
open the xml document in a browser, then you will see what I mean. This is
a good thing, believe it or not -- having access to all the information,
well-structured, like that. Also notice that an xml document is a tree --
with a root node (in this case <odsxml>) and many children, grand-
children, great grand-children ... nodes.
Sas dataset, however, is a table (with rows of column values). When you
import xml into a sas data set, thus, you have to tell sas which nodes of
the tree you want to turn into table rows and which into column values
(unless your xml document is already structured as a table). You do this
with xmlmap. You can code the xmlmap by hand, or rely on a utility program
that comes with sas 9, called "XML Mapper."
After studying the output xml file, I decide to make each "data" node into
rows (which also become the imported data set name), with the "name"
attribute as a column called "name", and its child node, "value", as a
column called "value".
The XML mapper also generates sas code, which includes filename and
libname statements. Below is an example. HTH.
Cheers,
Chang
<sasl:code ver="9.1.2" sysscp="WIN">
/* export the results of proc means to an xml file */
ods xml file = "c:\meanAir.xml";
proc means data = sashelp.air;
var air;
run;
ods xml close;
/* import summary statistics using xmlmap.
the map file and the filename libname statements
are generated by using "XML Mapper" */
filename meanAir 'C:\meanAir.xml';
filename SXLEMAP 'C:\MeansSummary.map';
libname meanAir xml xmlmap=SXLEMAP access=READONLY;
/* read in the xml document extracting two columns */
proc print data=meanAir.data;
title "meanAir";
run;
title;
/* on log
meanAir
Obs name value
1 n 144
2 mean 280.2986
3 stddev 119.9663
4 min 104
5 max 622
*/
/* content of c:\MeansSummary.map
<?xml version="1.0" encoding="windows-1252"?>
<!-- ############################################################ -->
<!-- 2004-10-09T22:43:59 -->
<!-- SAS XML Libname Engine Map -->
<!-- Generated by XML Mapper, 9.1.10.20040324.1139 -->
<!-- ############################################################ -->
<!-- ### Validation report ### -->
<!-- ############################################################ -->
<!-- Map validation completed successfully. -->
<!-- ############################################################ -->
<SXLEMAP version="1.2" name="MeansSummary">
<!-- ############################################################ -->
<TABLE name="data">
<TABLE-PATH syntax="XPath">/odsxml/body/proc/branch/leaf/output/output-
object/output-body/row/data</TABLE-PATH>
<COLUMN name="name">
<PATH syntax="XPath">/odsxml/body/proc/branch/leaf/output/output-
object/output-body/row/data/@name</PATH>
<TYPE>character</TYPE>
<DATATYPE>string</DATATYPE>
<LENGTH>6</LENGTH>
</COLUMN>
<COLUMN name="value">
<PATH syntax="XPath">/odsxml/body/proc/branch/leaf/output/output-
object/output-body/row/data/value</PATH>
<TYPE>numeric</TYPE>
<DATATYPE>double</DATATYPE>
</COLUMN>
</TABLE>
</SXLEMAP>
*/
</sasl:code>