Exploring OLAP Cubes With SAS EG
Exploring OLAP Cubes With SAS EG
Paper 044-2008
An Added Dimension: Exploring OLAP Cubes with SAS® Enterprise Guide®
Rupinder Dhillon, Dhillon Consulting Inc., Toronto, ON, Canada
ABSTRACT
The amount of data that is captured electronically is increasing at an exponential rate. While advances in
scalable storage solutions allow companies to house this data, those tasked with analyzing and
summarizing it now find themselves faced with the following questions:
• How do we turn raw data into useful information?
• How do we surface this information in a meaningful way?
• How do we provide access to all facets of the information that people may need to see?
To tackle these and other dilemmas, more and more organizations are turning to OLAP Cubes. OLAP, or
Online Analytical Processing, provides a multi-dimensional view of aggregated data. It provides quick and
easy access to facts, figures and statistics and gives the user the flexibility to change the view of the data to
hone in on the aspects that are most pertinent to them. With the latest incarnation of SAS Enterprise Guide,
SAS Programmers can also take advantage of the benefits of storing data in OLAP cubes.
WHAT IS OLAP?
Many user-applications require immediate results based on huge volumes of data. Most users do NOT want
to submit a job that churns away for hours before providing their results. With that in mind, if an application
can be sourced from summarized data, then OLAP can help. OLAP, or Online Analytical Processing,
allows a user to access and analyze summarized data (an OLAP cube) including the ability to quickly switch
to different views of the aggregated business data (Slice and Dice).
OLAP TERMINOLOGY
Let’s start by tackling some basic OLAP terminology. In the cube above, the colors represent different
groupings of data into logical categories, called dimensions. Dimensions might include Product,
Geography, Job Roles, Time, etc. The order in which you get information from the summary down to the
detailed data is specified by a hierarchy. For example, the Geography dimension might be ordered as
1
SAS Global Forum 2008 Beyond the Basics
continentÎcountryÎprovinceÎcity, with continent being the highest level of aggregation and city being the
most detailed. The data values that are summarized and used for analysis are measures. A slice is a
subset of the data that is available in the cube. The different groups of data that are summarized for easy
and fast access are referred to as aggregations.
Cubes can be created using a single source of underlying data or can be created by using a series of tables
connected by various keys. When creating a cube from a single table, you source the data from a Detail
Table which contains the measures and levels (for defining the hierarchies). When using a series of tables,
the underlying data structure is a Star Schema, which uses a Fact table along with a set of Dimension
tables to define the cube.
PROC OLAP
This example uses PROC OLAP to create a cube based on a single detail table, the Shoes dataset in the
SASHELP library. The cube was created using the Program_1 SAS code included in the appendix. This
code will register the metadata for your underlying Detail table; it will create the OLAP cube and register the
cube details in the metadata server. Let’s take a quick look at the PROC OLAP syntax.
** Define measures based on built in metrics (ie. sum, average, mean etc)
MEASURE < >
STAT=SUM COLUMN= <>
CAPTION= '<>' FORMAT= <> ;
** Specify pre-aggregations
AGGREGATION < > / NAME='< > ' ;
2
SAS Global Forum 2008 Beyond the Basics
In addition to the PROC OLAP code, we’ve included some additional steps in this program. The PROC
METALIB step will refresh the metadata for the underlying data table, in our case a copy of the
SASHELP.SHOES dataset. It is important to refresh the metadata for the underlying table since your table
structure could have changed to include additional fields or different formats. We’ve also set many of the
metadata system options for the session, saving us from having to specify the metadata details in the OLAP
procedure. This is something that you may want to consider doing if you’re building several OLAP cubes in
the same program.
Presently, SAS does not support incremental Cube updates so the cube has to be reloaded with all data
each time it is refreshed. If your process updates or refreshes existing cubes, you will need to add a PROC
OLAP DELETE step to your code:
• DELETE – will delete the physical cube and all metadata associated with the cube. Use this option
when you are changing or adding dimensions, hierarchies, measures or descriptions.
• DELETE_PHYSICAL – will only delete the physical data stored in the cube. Use this option when
you want to change or update or add data to in the cube without changing the structure.
Note: Incremental updates will be introduced in 9.2.
• To open the Olap Cube in Enterprise Guide , click File Î Open Î Olap Cube
• Dependent upon your setup, enter the following into the Open OLAP Window ( place information
specific to your setup where the *** appear) :
o Olap Server Name: ****************
o Provider: SAS OLAP Data Provider 9.1 (from drop down list)
o User Name: ******
o Password: *******
• Click Connect
• Check the box next to your newly created Cube – click Open.
3
SAS Global Forum 2008 Beyond the Basics
Table View
Graph View
Cube View Manager: Allows you to display various dimensions and hierarchies in the table and graph
view, customize preferences for the current cube and create shortcuts and filtered views of the data.
Table View: Shows cube data in a table format and allows you to expand levels and drill down on the data.
Graph View: Automatically updates to reflect the data shown in the table view. You can customize the
graph layouts and export to other Windows tools.
Cube Viewer Menu Bar: Shortcut buttons to toggle between views (back, forward), customize view (View
designer), view the MDX behind the current view, add new measures, filter the data and turn graph and tree
views on and off.
You can close the Cube View Manager to create more space by clicking the ‘X’ in the upper right-hand
corner of the Cube View Manager window. Note that these options (Dimensions, Preferences and
Shortcuts) are now hidden tabs along the left hand side of your cube viewer and can be viewed simply by
clicking on them.
4
SAS Global Forum 2008 Beyond the Basics
• You’ll notice that you now have a SLICER view above your table view. The cube slicer allows you to
filter the various dimensions. In this view we are looking at ALL product types and ALL regions.
Cube Slicer
• Let’s drill back up to the aggregated view of all products. Right click on the Product Hierarchy cell
(where the Hierarchy level name is in Italics).
o Select Drill Up To Î All Product_Type
• Change the displayed measure. Right click on the ‘MeasureLevel.’ and select ‘Edit Measures’
5
SAS Global Forum 2008 Beyond the Basics
• Take a closer
look at Canada
• Right click
anywhere on the
Canada cell.
Click ‘Isolate
Canada’
Move the Products dimension from the columns to the rows. Right click on any of the Product Column
headings, click Move Product Î To rows.
• What if we wanted to
see a breakdown of
products by region?
Right click on the ALL
Product Type
Dimension level, select
Drill Down to Product.
Notice that our Slicer now tells us that we are looking at All Product Types in the Product dimension but
only Canada in the Division Dimension. When slicing and dicing Cubes, you can sometimes lose track of
the path you’ve taken to get a certain view. The Slicer view helps you keep track of what subset of data
you’re looking at.
6
SAS Global Forum 2008 Beyond the Basics
Slice Info
There are other features that are available in the cube viewer that help when exploring your cube data.
Among other things, the cube viewer allows you to filter the data based on constraints that you define, you
can order the data, you can create bookmarks or shortcuts to certain views, and you can create your own
custom measures that may not already exist in the cube definition. Once you are comfortable with slicing
and dicing your data views, I would encourage you to become familiar with some of these additional features
available.
INCORPORATING OLAP INTO YOUR SAS PROGRAMS
Now that the OLAP cube is created and we have a better idea of the data available in the cube, we want to
be able to use the aggregated data to create some reports. We’ve heard that taking advantage of
organized dimensions, hierarchies and pre-aggregated data makes querying an OLAP cube is a lot faster
than querying raw data tables but how do we actually query a cube from our SAS code?
Using PROC SQL (specifically the SQL pass-through facility for OLAP), you can connect to your cube and
query the data like you would a SAS dataset or Database table. The query language that you use is called
MDX and while it uses the familiar SQL keywords (select, from, where), that’s where the similarities end. So
how do you connect to a cube through your code? First, let’s look at the familiar syntax (see Program_2 in
Appendix)
Before we tackle the MDX query, let’s take a quick look at the options needed to connect to the cube:
Many of these options will be provided to you by your Administrator. Building the MDX select code is a
*little* trickier:
7
SAS Global Forum 2008 Beyond the Basics
Since Enterprise Guide has a built-in cheat sheet within its OLAP Cube Viewer, you can get away with not
knowing much (if any) MDX syntax. You can use the MDX Editor in the Cube Viewer to build and tweak
your query code. Simply navigate to the desired Cube view and copy the MDX query code that is built for
you.
Let’s go back to our Olap Cube viewer and get our MDX Query code.
• To view the MDX code from the Main Menu Select OLAPÎ View MDX or click
the MDX Editor button in your Cube Viewer Window
The data pulled by the PROC SQL step is available to the rest of your SAS code as a SAS dataset. Note
that since the data we extracted is already pre-aggregated, we don’t have to perform any additional
summarizing on the data. A simple proc report is run on the data to output it in the appropriate format.
In addition to querying the cube using PROC SQL, you can generate a SAS dataset by creating a ‘slice’
from your Cube view. You may want to do this in order to a) preview the SAS dataset that will be generated
by the MDX query to ensure that it captures the data how you intended or; b) create a dataset for any ad hoc
analysis you are doing in Enterprise Guide.
8
SAS Global Forum 2008 Beyond the Basics
Now that the cube data view is available as a dataset, it can be:
What if you wanted to capture the Cube View in the table format displayed in the Cube Viewer rather than as
a SAS dataset? In this case you’d want to create a Report Snapshot.
• To create a Report
Snapshot of the view
you are looking at,
return to your
Process Flow in the
Project Designer
View
9
SAS Global Forum 2008 Beyond the Basics
The Report Snapshot is a static HTML copy of the Cube view and will open as a new tab in Enterprise
Guide.
There are a number of ways you can customize and use this report snapshot. You can modify it by
changing the page set up, adding headers and footers and changing the style template applied to the
snapshot. You’ll notice that a grid called SAS Reports has been added to your Enterprise Guide project
(next to the Process Flow tab). By right clicking on the Report Snapshot icon that has been added the
SAS Reports grid, you can Export the snapshot to other Windows applications, send the snapshot to an
email recipient, rename or delete the snapshot and also update its properties.
10
SAS Global Forum 2008 Beyond the Basics
The export functionality allows you to export the table and save it as Excel, Word or other Windows format
files. You can also simply right click copy and paste the Report Snapshot table into Excel and preserve the
formatting.
11
SAS Global Forum 2008 Beyond the Basics
It’s important to remember that if your Graph View is still switched on in your Cube Viewer, the graph
corresponding to your data view will also be captured in your Report Snapshot.
Proc SQL;
Connect to OLEDB (provider= MSOLAP
props=(‘DATA SOURCE’ = SQL Server Name
‘USER ID’ = User Id
PASSWORD = Password
‘INITIAL CATALOGUE’ = CubeName ));
Create table MYDATA as select * from connection to OLEDB
( select <MDX query here>)
Quit;
Run;
There are other Properties (or PROPS) statements that may be required depending on your environment.
For a complete description of all connection options as well as further discussion on querying Microsoft
Cubes, please refer to the recommended reading links at the end of this paper.
CONCLUSION
This paper has shown how Enterprise Guide provides SAS Programmers with a method of exploring and
querying OLAP Cubes. With the basics in place, you can now start exploring ways to build on this
knowledge by looking at incorporating OLAP querying into your SAS Stored Processes, Enterprise Guide
Projects or custom SAS applications. By applying your own SAS expertise, you can use OLAP cubes to
build unique Reporting Solutions and tackle other data presentation requirements facing your organization.
12
SAS Global Forum 2008 Beyond the Basics
RECOMMENDED READING
To gain a more complete understanding of Enterprise Guide 4.1 and using SAS OLAP Cubes, the author
recommends the following web links.
• Getting Started with SAS Enterprise Guide – free learning tutorial available from
http://www.sas.com/apps/elearning/elearning_details.jsp?pubcode=59271
• Getting started with SAS/ACCESS Interface to OLE DB – SAS Tech Note
http://support.sas.com/techsup/technote/ts700.pdf
• To Cube or Not to Cube: Is OLAP the Better Choice? – SAS Global Forum 2007 Paper
http://www2.sas.com/proceedings/forum2007/013-2007.pdf
• Beyond the Basics: Advanced OLAP Techniques – SAS Global Forum 2007 Paper
http://www2.sas.com/proceedings/forum2007/232-2007.pdf
ACKNOWLEDGMENTS
This paper is an extension of the information presented in the SAS Global Forum 2007 paper 110-2007, A
® ® ®
“SAS Programmer’s” Guide to SAS Enterprise Guide , coauthored by Marje Fecht. Special thanks to
Marje for her extensive input.
CONTACT INFORMATION
Your comments and questions are valued and encouraged. Contact the author at:
Rupinder Dhillon
Dhillon Consulting
[email protected]
www.dhillonconsulting.com
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of
SAS Institute Inc. in the USA and other countries. ® indicates USA registration.
Other brand and product names are trademarks of their respective companies.
13
SAS Global Forum 2008 Beyond the Basics
APPENDIX – PROGRAMS
PROGRAM_1
option metaserver="&SERVER"
metaport=&PORT
metaprotocol="&PROTOCOL"
metarepository="&REPOSITORY"
metauser="&USER"
metapass="&PASSWORD";
data &libname..shoes;
set sashelp.shoes;
run;
LEVEL Subsidiary
14
SAS Global Forum 2008 Beyond the Basics
CAPTION='Subsidiary'
SORT_ORDER=ASCENDING
;
LEVEL Region
CAPTION='Region'
SORT_ORDER=ASCENDING
;
LEVEL Product
CAPTION='Product'
SORT_ORDER=ASCENDING
;
MEASURE ReturnsSUM
STAT=SUM
COLUMN=Returns
CAPTION='Sum of Returns'
FORMAT=DOLLAR12.
DEFAULT
;
MEASURE InventorySUM
STAT=SUM
COLUMN=Inventory
CAPTION='Sum of Inventory'
FORMAT=DOLLAR12.
;
MEASURE SalesAVG
STAT=AVG
COLUMN=Sales
CAPTION='Average Sales'
FORMAT=DOLLAR12.
;
MEASURE SalesSUM
STAT=SUM
COLUMN=Sales
CAPTION='Sum of Sales'
FORMAT=DOLLAR12.
;
MEASURE StoresSUM
STAT=SUM
COLUMN=Stores
CAPTION='Sum of Stores'
FORMAT=12.
;
AGGREGATION Region
Subsidiary
15
SAS Global Forum 2008 Beyond the Basics
Product
/ NAME='DEFAULT'
;
DEFINE
MEMBER '[SampleCube].[Measures].[Sales per Store]' AS
'
([Measures].[SalesSUM] / [Measures].[StoresSUM]) , FORMAT_STRING = "dollar30."';
RUN;
PROGRAM_2
Proc SQL;
Connect to OLAP (host="&server" port=&olap_port protocol=&protocol user="&user"
pass="&password"
repository="&repository"
olap_schema="&schema");
16