BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
Cynthia_sas
Diamond | Level 26
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]
deleted_user
Not applicable
Hi Priya,
Are you working as a SAS programmer.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 2 replies
  • 4986 views
  • 1 like
  • 2 in conversation