BookmarkSubscribeRSS Feed
jj_mk
Calcite | Level 5

Does anyone know if it is possible to combine multiple datasets when exporting to a single XML file?

The specific example I have in mind is as follows:

1. Required XML Logical structure

Our customers can have one or more accounts and can belong to one or more customer groups, so the structure of XML that I need to create is one record per customer and multiple sub-records at the same hierarchical level for each account and customer group, i.e. something like the following:

<customer>

   <customer_id>1234</customer_id>

   ...other customer attributes...

 

   <subrecord - account>

    <account_id>ACCT0001</account_id>

    ...account attributes...

   </subrecord>

 

   <subrecord - account> 

     <account_id>ACCT0002</account_id> 

    ...account attributes...

   </subrecord>

     <subrecord - customer type>   

     <cust_type_id>BUSINESS</account_id> 

    ...customer type attributes...

   </subrecord>

</customer>

2. Current SAS data structures

Currently the data that I need to build the XML from is stored in 3 tables.

a) Customer which is keyed on customer_id.

b) Customer_accounts which is keyed on customer_id and account_id

c) Customer_types which is keyed on customer_id and cust_type_id.

3. Approach

I can build the required XML file in an old school way by using a data step that incorporates a set statement for each of the (sorted) tables listed above with multiple put statements. However, even though this works I am wondering whether there is a more efficient (i.e faster in elapsed time) way to do this using the XML engine or other more recently developed SAS tool.

After searching online I've not found any examples of XML exports that use multiple tables. If I can only use a single dataset then this implies that I have to restructure the input data by merging into a single table that has duplicate customer (and potentially account) values across multiple records. Can I configure the XML hierachy to create the multiple sub-record types that I will need?

Apologies if this hasn't been posted to the correct community - I wasn't sure of the most appropriate place.

Thanks in advance.

Jonathan

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, my first answer would have been code it by hand as you have full functionality then, but I see reading down you already know that.  The only other thing I can think of is to write a tagset.  Right click on Results in the results window and select templates.  Then navigate to Excelbase for instance and you can see the one developed for Export To ExcelXP.  However its a fair bit of work, so if its just for a one off, your probably better with the put statements.

Kurt_Bremser
Super User

tagsets.excelxp, for instance, can put the results of several steps into one xml file.

If you want a customized xml structure, you will need a fitting tagset, or you do it by hand in a data step. And I don't think you can beat a properly written data step, timewise.

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
  • 2 replies
  • 1338 views
  • 0 likes
  • 3 in conversation