How to create a XML format using SAS?

Reply
Occasional Contributor
Posts: 14

How to create a XML format using SAS?

Hi all,

I have created the XML file from my data set but I need to add some more tags to that XML file. How should I do that??

Super Contributor
Posts: 543

Re: How to create a XML format using SAS?

Could you provide more detail on how you created the XML file?

Using XMLMapper? or ODS Tagsets? or...?

Thanks.

Occasional Contributor
Posts: 14

Re: How to create a XML format using SAS?

Posted in reply to AncaTilea

I got the XML file required but I also have to put header on that file with some titles.

Occasional Contributor
Posts: 14

Re: How to create a XML format using SAS?

I used XML engine with the help of LIBNAME statement.

SAS Super FREQ
Posts: 8,864

Re: How to create a XML format using SAS?

Hi:

  There are several ways to create XML files from SAS datasets. Did you use the SAS XML Libname Engine? The engine can be used stand-alone or with an XML Map. To design your XML Map file, you can use the SAS XML Mapper. Or, you can use a custom tagset template to work with either ODS or with the XML Libname engine.

  Generally, SAS "likes" to generate very simple XML...such as you would get from submitting the code below. Note that there is a HUGE difference between the output generated by the SAS XML Libname engine and ODS (by default). So, when you say you need to insert more tags into your XML file, this generally points to a change of the TAGSET template used by your method (either the engine or ODS). I've pasted some code below that shows the kind of simple XML that SAS likes to create. Open the files in Notepad or an XML Editor to see the structure of the tags.

  This is a very old (pre 9.2) paper on the topic of customizing. http://www.lexjansen.com/pharmasug/2006/technicaltechniques/tt24.pdf This paper pre-dates the ability to create XML from SAS using XML Mapper. You would have to refer to the doc if you have 9.2 or higher and you want to generate custom XML from a SAS dataset using an XML Map.

cynthia

** some code;

title; footnote;
options nodate nonumber;
** 1) Using the SAS XML Libname Generic format;
libname xmlout xml "c:\temp\females_15_over.xml"
        xmltype=generic;

data xmlout.class;
  set sashelp.class;
  where age ge 15 and sex = 'F';
run;
libname xmlout clear;
  
** 2) Using the SAS XML Libname engine with the Oracle XML format;
libname xmlout xml "c:\temp\females_15_oracle.xml"
        xmltype=oracle;

data xmlout.class;
  set sashelp.class;
  where age ge 15 and sex = 'F';
run;
libname xmlout clear;
  
** 3) use ODS XML to make an XML "report" from PROC PRINT;
ods xml file='c:\temp\classreport.xml';

proc print data=sashelp.class noobs;
  title 'This is a Report View of my Data';
  where age ge 15 and sex = 'F';
run;

ods xml close;

Occasional Contributor
Posts: 14

Re: How to create a XML format using SAS?

Posted in reply to Cynthia_sas

Hey Cynthia thanx for your advice.

I had already used two ways out of three.

I got output too but I need to add some more tags to that XML file.How I do that.

For example: After running the code you gave, I got:-

<?xml version="1.0" encoding="WINDOWS-1252"?>

-<TABLE>

-<CLASS>

<Name> Janet </Name>

<Sex> F </Sex>

<Age> 15 </Age>

<Height> 62.5 </Height>

<Weight> 112.5 </Weight>

</CLASS>

-<CLASS>

<Name> Mary </Name>

<Sex> F </Sex>

<Age> 15 </Age>

<Height> 66.5 </Height>

<Weight> 112 </Weight>

</CLASS>

</TABLE>

But I want like this


<?xml version="1.0" encoding="WINDOWS-1252"?>

<HEADER>

<CLASS NAME> SIXTH <CLASS NAME>

<CLASS SECTION> C <CLASS SECTION>

</HEADER>

-<TABLE>

-<CLASS>

<Name> Janet </Name>

<Sex> F </Sex>

<Age> 15 </Age>

<Height> 62.5 </Height>

<Weight> 112.5 </Weight>

</CLASS> -<CLASS>

<Name> Mary </Name>

<Sex> F </Sex>

<Age> 15 </Age>

<Height> 66.5 </Height>

<Weight> 112 </Weight>

</CLASS>

</TABLE>

Ask a Question
Discussion stats
  • 5 replies
  • 249 views
  • 0 likes
  • 3 in conversation