Discussion:
xml data read in does not exist?
(too old to reply)
Aldi
2004-10-09 23:47:35 UTC
Permalink
Hi,
I am trying to read some doc in xml using sas v9.1 for win, os=xp.

To test another work which is is not working, here is an example:

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?

92 libname trans xml 'c:\aldi2\xml\exercise5.xml';
NOTE: Libref TRANS was successfully assigned as follows:
Engine: XML
Physical Name: c:\aldi2\xml\exercise5.xml
93 proc print data=trans.exercise5;
ERROR: File TRANS.EXERCISE5.DATA does not exist.
94 title "ex5";
95 run;

TIA,
Aldi
Chang Y. Chung
2004-10-10 03:26:26 UTC
Permalink
Post by Aldi
Hi,
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>
Alan Churchill
2004-10-10 04:00:33 UTC
Permalink
When you read in XML, it will treat your top level elements as the table names. For example, take a look at this XML:



<testdata>

<record>

<age>25</age>

</record>

</testdata>



If I then save that file as &lsquo;c:\temp\test.xml', I would then read it in as the following:



libname mydata xml &lsquo;c:\temp\test.xml' ;



data mydata.testdata;

&hellip;

run;



You are trying to use the physical file name as the dataset rather than the actual table name held within XML.



Hope that helps.





Alan

Savian

"Bridging SAS and Microsoft technologies"







nntp://news.qwest.net/comp.soft-sys.sas/<***@corp.supernews.com>

Hi,

I am trying to read some doc in xml using sas v9.1 for win, os=xp.



To test another work which is is not working, here is an example:



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?



92 libname trans xml 'c:\aldi2\xml\exercise5.xml';

NOTE: Libref TRANS was successfully assigned as follows:

Engine: XML

Physical Name: c:\aldi2\xml\exercise5.xml

93 proc print data=trans.exercise5;

ERROR: File TRANS.EXERCISE5.DATA does not exist.

94 title "ex5";

95 run;



TIA,

Aldi



[comp.soft-sys.sas]

Continue reading on narkive:
Loading...