Published on :
ETL SASHELP

Exporting SAS Data to XML (MS Access)

This code is also available in: Deutsch Español Français
Awaiting validation
The script first initializes an XML library ('access') pointing to 'd:\test.xml', configured for MS Access format with schema metadata. Then, a DATA step creates a temporary dataset named 'test' in the WORK library, populating it with data from 'sashelp.retail' and adding an index on the 'year' and 'month' variables. Finally, PROC COPY is used to copy this 'test' dataset from WORK to the 'access' XML library, which has the effect of exporting it to the 'd:\test.xml' file. The session ends by releasing the 'access' library.
Data Analysis

Type : SASHELP


Data comes from the internal dataset 'sashelp.retail'. The XML file 'd:\test.xml' is the export destination.

1 Code Block
LIBNAME
Explanation :
Defines the libname 'access' as an XML library, linking it to the file 'd:\test.xml'. The options 'xmltype=msaccess' and 'xmlmeta=schemadata' specify the XML format for compatibility with MS Access and the inclusion of schema metadata.
Copied!
1LIBNAME access xml 'd:\test.xml'
2xmltype=msaccess xmlmeta=schemadata;
3 
2 Code Block
DATA STEP Data
Explanation :
Creates a temporary dataset named 'test' in the WORK library. It is populated with data from the 'retail' dataset in the SASHELP library. An index is also created on the 'year' and 'month' columns to optimize access.
Copied!
1 
2DATA test(index=(year month)) ;
3SET sashelp.retail ;
4RUN ;
5 
3 Code Block
PROC COPY
Explanation :
Copies the 'test' dataset from the WORK library to the 'access' library (the XML file 'd:\test.xml'). The 'index=yes' option ensures that all indexes defined on the source dataset are also copied to the destination.
Copied!
1 
2PROC COPY in=work out=access index=yes ;
3select test ;
4RUN ;
5 
4 Code Block
LIBNAME
Explanation :
Releases the libname 'access', dissociating the logical name 'access' from the file 'd:\test.xml'.
Copied!
1LIBNAME access ;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.