SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
demetri0
Calcite | Level 5

Hi everyone.

 

I'm trying to generate a bunch of XML files for a mail-out.  

 

I need to change the root tag from <TABLE> to <RECORD>. I also need to have this tag: <Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="1900C.xsd">.

 

 

/*This is a simplified example of the code I'm using*/

LIBNAME xmlout XML "&path.\HAVE.xml" xmlencoding="utf-8" tagset=tagsets.sasxmiss;

data xmlout.Recorddata;
	set Addresses;
	keep FormID SequenceNumber ClientCorrespondenceLanguage ClientIdentificationNumber 
		 ClientName ClientAddress1 ClientAddress2 ClientAddress3;
run;

THIS IS THE OUTPUT I HAVE

<?xml version="1.0" encoding="utf-8" ?>
<TABLE>
   <RECORDDATA>
      <FormID>1111</FormID>
      <SequenceNumber>00000001</SequenceNumber>
      <ClientCorrespondenceLanguage>E</ClientCorrespondenceLanguage>
      <ClientIdentificationNumber>111111111</ClientIdentificationNumber>
      <ClientName>John Doe</ClientName>
      <ClientAddress1>1 ELM ST</ClientAddress1>
      <ClientAddress2>ANYWHERE PE C1C 1C1</ClientAddress2>
      <ClientAddress3/>
   </RECORDDATA>
</TABLE>

THIS IS THE OUTPUT I WANT

<?xml version="1.0" encoding="utf-8"?>
<Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="1900C.xsd">
 <Records>
   <RECORDDATA>
      <FormID>1111</FormID>
      <SequenceNumber>00000001</SequenceNumber>
      <ClientCorrespondenceLanguage>E</ClientCorrespondenceLanguage>
      <ClientIdentificationNumber>111111111</ClientIdentificationNumber>
      <ClientName>John Doe</ClientName>
      <ClientAddress1>1 ELM ST</ClientAddress1>
      <ClientAddress2>ANYWHERE PE C1C 1C1</ClientAddress2>
      <ClientAddress3/>
   </RECORDDATA>
 </Records>

Any help would be appreciated.

 

Thanks.

 

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

A bit of post-processing:

data _null_;
 infile "&wdir\have.xml" ;
 file "&wdir\want.xml";
 input;
 if _INFILE_='<TABLE>' then put '<Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="1900C.xsd">'
    '0d0a'x '<Records>';
 else if _INFILE_='</TABLE>' then put '</Records>';
 else put _INFILE_;
run;

 

 

demetri0
Calcite | Level 5

Perfect!  Thanks very much.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 944 views
  • 2 likes
  • 2 in conversation