10
SAS Table Name SAS Label
Chemicals Chemicals
Graphics_cards Graphics Cards
Health___wellness_resources Health & Wellness Resources
_0_107_senate_voting 40-107 Senate Voting
AS tables created from Excel
READING EXCEL XML INTO SAS
You could use the SXLE and an XMLMap of your own creation to import an Excel XML file into SAS, but because the
Excel XML format and the data conversion issues are quite complex, SAS provides an XMLMap specific to Excel and
corresponding SAS code that loads the Excel XML into SAS tables. As mentioned earlier, both components as well
as a SAS macro to import the XML data, are available for download from the SAS Presents Web site. These
components may ship with future releases of SAS, so watch the Base SAS Community Web site for further details
(http://support.sas.com/rnd/base/
)
Download the XMLMap and the SAS macro and make the two files available on the platform where SAS is installed.
This paper assumes that you saved the SAS XMLMap in a file named "excelxp.map" and the SAS macro to load the
XML data was stored in a file named "loadxl.sas". The file "loadxl.sas" contains a SAS macro named XLXP2SAS,
which is used to import the XML file into SAS tables.
The easiest way to explain how to use the macro is with a few examples. First, we will consider importing the XML
workbook shown in Figure 7 when either SAS is installed on the same machine that has the XML file or SAS is
installed on a different machine or platform, but the XML file is accessible via a network drive. To import the
workbook into SAS, submit this code, making sure to include the appropriate directory paths:
n %include 'loadxl.sas';
o %xlxp2sas(excelfile=mydata.xml,
mapfile=excelxp.map);
The statement at n makes the XLXP2SAS macro available to SAS. The statement at o imports the data from all the
worksheets into separate SAS tables. By default the SAS tables are created in the WORK library. You can control
the library used to store the SAS tables by specifying the LIBRARY argument of the XLXP2SAS macro. For example,
to store the tables in the SASUSER library, submit this code:
%xlxp2sas(excelfile=mydata.xml,
mapfile=excelxp.map,
library=sasuser);
Table 2 lists the SAS tables
created as a result of importing
the Excel workbook shown in
Figure 7. Note that while the
table names may look a bit odd,
the actual worksheet names are
used in the SAS labels.
Figure 8 (below) shows a portion of the "Graphics_cards" table. By comparing Figures 7 and 8, you can see that the
XLXP2SAS macro successfully imported the "Graphics Cards" worksheet as a SAS table. For instance, the columns
"Pixel pipelines" and "Memory bus width (bits)" were both correctly typed as character, because those columns
contain data such as "2*2" and "128*2", respectively.
Up to this point the assumption is that the XML file resides on the same machine as SAS or it was available via a
network accessible drive. However, if the XML file resides on the Web server of a remote machine, you can use the
URL access method to retrieve the file by submitting the following code:
filename myxml URL 'http://Web-server/mydata.xml';
%xlxp2sas(excelfile=FILEREF:myxml,
mapfile=excelxp.map);
Ins & OutsNESUG 17