How to convert SAS datasets to XML?

Reply
N/A
Posts: 0

How to convert SAS datasets to XML?

Hi All,

I need some means to convert SAS Datasets to XML with SAS 8.2. Isit possible to do in 8.2?

I need a solutions asap.
Thanks,
Priya
SAS Super FREQ
Posts: 8,820

Re: How to convert SAS datasets to XML?

Hi:
Yes, the SAS XML Libname engine worked in SAS 8.2 to convert a SAS dataset to an XML file. ODS MARKUP also worked in SAS 8.2 to convert procedure output (such as PROC PRINT) to an XML version of the report.

Probably in your instance, you want the SAS XML Libname engine. It produces very generic, very "flat" XML.

If your XML needs to conform to some standard or specification (such as CDISC), then you might consider checking out PROC CDISC before you go too far down the XML Libname Engine road.
http://support.sas.com/rnd/base/xmlengine/index.html
http://support.sas.com/rnd/base/xmlengine/proccdisc/index.html

There is an example below of using the SAS XML Libname engine to create an xml file from a SAS dataset.

cynthia

[pre]
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;
[/pre]

The XMLTYPE=GENERIC is the default and you don't need that option if you want the default. But XMLTYPE is one way to change the type of XML that's created. The example produces this XML file for the "generic" example:
[pre]
<?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>
[/pre]

Then, if you change the XMLTYPE= to XMLTYPE=ORACLE, then this file is what you'd get for the XML output:
[pre]
<?xml version="1.0" encoding="windows-1252" ?>
<ROWSET>
<ROW>
<Name> Janet </Name>
<Sex> F </Sex>
<Age> 15 </Age>
<Height> 62.5 </Height>
<Weight> 112.5 </Weight>
</ROW>
<ROW>
<Name> Mary </Name>
<Sex> F </Sex>
<Age> 15 </Age>
<Height> 66.5 </Height>
<Weight> 112 </Weight>
</ROW>
</ROWSET>

[/pre]
N/A
Posts: 0

Re: How to convert SAS datasets to XML?

Hi Priya,
Are you working as a SAS programmer.
Ask a Question
Discussion stats
  • 2 replies
  • 1769 views
  • 1 like
  • 2 in conversation