BookmarkSubscribeRSS Feed
DavidJ
Calcite | Level 5
Running SAS 9.2, Phase 2 (TS2M0)
Can XMLMap assist with creating a SAS dataset such as the following XML describes:


Value
etc...


Value
etc

Value
etc




I don't have a schema file (XSD) yet.
- There can be 1 to many Reports in the file
- The subrecord section can occur 0 to unbounded

When we tried to read a file with one record, we ended up with Header, Info and Subrecord datasets, and many of the fields were set to missing. XML engine, tried several XMLTYPES (did not use XMLMAP).

I need the following from the 1 report record:
Header, Info and unique subrecord(s), 1 obs. per subrecord, header and info repeating. So if there were 3 subrecords within the one record, I'd have 3 records with the other fields carrying thru.

Can this be done within SAS using the mapper, XML or XML92 engines? We are under a tight deadline. Any ideas appreciated.
1 REPLY 1
Cynthia_sas
SAS Super FREQ
Hi:
I'm confused....this XML describes one or more REPORTS and you want to convert the report information into a -single- SAS dataset??? I believe this is the kind of thing you will definitely need to do with an XMLMAP to read the ????? data/report.

Is there data in the XML that is all that needs to be extracted????? Do you have an example of a "real" file. Using the XMLMapper (which is a Java application that allows you to map your XML to a SAS dataset), you can map how you want your SAS dataset to be built. Or, you could try writing the map syntax on your own.

By default, the SAS XML Libname engine expects very regular, non-hierarchical (flat) XML to read. Your XML file needs to be flat (one root tag, one observation boundary tag, one tag for every field), like this in order to read it without an XML Map:
[pre]
<?xml version="1.0"?>
<gifttable>
<giftidea>
<Name>Alan</Name>
<Idea>Books</Idea>
<Limit>$60</Limit>
</giftidea>
<giftidea>
<Name>Barb</Name>
<Idea>Jewelry</Idea>
<Limit>$25</Limit>
</giftidea>
<giftidea>
<Name>Carl</Name>
<Idea>Bike Gear</Idea>
<Limit>$75</Limit>
</giftidea>
. . . more tags . . .
</gifttable>

[/pre]

In the above XML, I have the required XML processing instruction; one root tag GIFTABLE, one observation boundary that contains my variables GIFTIDEA, and 3 tags for 3 fields, NAME, IDEA and LIMIT. So, my SAS variables would become NAME, IDEA and LIMIT and every observation would be composed of the tags that were contained within one <GIFTIDEA>/</GIFTIDEA> pair of tags.

...If your XML file is not "flat" like this, then the only way to deal with the file is 1) transform the XML to be flatter (using 3rd party tools or an XSL transform) so you can read it with the "vanilla" SAS XML Libname Engine or 2) read the file with an XML Map.

Here is a resource page:
http://support.sas.com/rnd/base/xmlengine/index.html

cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 780 views
  • 0 likes
  • 2 in conversation