BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_Deepak
Calcite | Level 5

Hi Guys,

 

I want to export the SAS Data set in XML through SAS code.

How I can do that?

 

Do the needful.

 

Thanks and Regards.

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASJedi
Ammonite | Level 13

The simplest method is to use the SAS LIBNAME XMLV2 engine.  Something like this would work:

filename classXML 'C:\temp\class_data.xml';
libname classXML xmlv2;
proc copy in=sashelp out=classXML;
   select class;
run;
libname classXML clear;
filename classXML clear;

This produces the following XML file:

<?xml version="1.0" encoding="windows-1252" ?>
<TABLE>
   <class>
      <Name>Alfred</Name>
      <Sex>M</Sex>
      <Age>14</Age>
      <Height>69</Height>
      <Weight>112.5</Weight>
   </class>
   <class>
      <Name>Alice</Name>
      <Sex>F</Sex>
      <Age>13</Age>
      <Height>56.5</Height>
      <Weight>84</Weight>
   </class>
</TABLE>




Check out my Jedi SAS Tricks for SAS Users

View solution in original post

3 REPLIES 3
SASJedi
Ammonite | Level 13

The simplest method is to use the SAS LIBNAME XMLV2 engine.  Something like this would work:

filename classXML 'C:\temp\class_data.xml';
libname classXML xmlv2;
proc copy in=sashelp out=classXML;
   select class;
run;
libname classXML clear;
filename classXML clear;

This produces the following XML file:

<?xml version="1.0" encoding="windows-1252" ?>
<TABLE>
   <class>
      <Name>Alfred</Name>
      <Sex>M</Sex>
      <Age>14</Age>
      <Height>69</Height>
      <Weight>112.5</Weight>
   </class>
   <class>
      <Name>Alice</Name>
      <Sex>F</Sex>
      <Age>13</Age>
      <Height>56.5</Height>
      <Weight>84</Weight>
   </class>
</TABLE>




Check out my Jedi SAS Tricks for SAS Users
SAS_Deepak
Calcite | Level 5
Thank you
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
  • 3 replies
  • 1002 views
  • 0 likes
  • 3 in conversation