importing and displaying data using sas enterprise … and displaying data using sas® enterprise...

13
1 Importing and Displaying Data Using SAS ® Enterprise Guide ® : Las Vegas Style R. Scott Leslie, STATisfy Analytics, San Diego, CA ABSTRACT SAS ® Enterprise Guide ® allows users to import and display data quicker and easier than ever. The Import Data wizard contains multiple options to transform Excel spreadsheets into clean SAS data sets which can then be displayed as charts, tables and graphs with the use of several available Task wizards. Topics covered in this paper include navigating Enterprise Guide menus, importing Excel spreadsheets using the Import Data wizard, summarizing data sets with Task wizards, and using the Report Layout tool to create a PDF of your final output. US Census and publicly available real estate data on Las Vegas are used to demonstrate these effective Enterprise Guide features. INTRODUCTION This paper provides two examples of using the Import Data wizard to import Excel spreadsheets as SAS data sets. The first example is a rather simple example using a clean spreadsheet. Since many spreadsheets are not created for the purpose of using within SAS, the next example presents hints for how to import spreadsheets with multiple header rows and how to format variable during an import. Once a SAS data set is created, a logical next step is to profile the data set. This is easily done with task wizards that can display data concisely with charts and graphs. Subsequently, content created by task wizards is easily assembled using the Report Builder function which allows exporting SAS reports as PDF or HTML files. This paper is intended for SAS users with less experience with Enterprise Guide or those in need of handy tips on automating code and processes within an Enterprise Guide project. QUICK REVIEW OF THE ENTERPRISE GUIDE INTERFACE This section is a brief overview of the Enterprise Guide interface. For those familiar with the look of Enterprise Guide, please look forward to the next sections of this paper. At first glance, the application looks very menu driven and can be unpleasant to traditional SAS programmers. It took me a while to reconcile the log and output windows. After time, I came to realize that the interface has many more features than the Display Manager seen in SAS. The key to getting accustomed to Enterprise Guide is learning how to work with process flows. First, all work is organized in one file called a Project with the file extension “.epg”. A sample project is shown below. All code, data, log and output are contained in the project and represented as Nodes (the icons) shown in the Process Flow window below. So the process flow represents your desktop that charts all your work. I find this process flow window useful because projects can be broken into steps. For example, instead of 1000 lines of code in one program that don’t have natural breaks you can have 4 or 5 programs as steps within a process flow. This is explained later in the paper. The Process Flow and Project Tree windows give programmers an easy view of your entire project. Display 1. SAS Enterprise Guide Interface

Upload: lykhuong

Post on 12-Jun-2018

231 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Importing and Displaying Data Using SAS Enterprise … and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued 2 CHANGING SAS ENTERPRISE GUIDE SETTINGS If you

1

Importing and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style

R. Scott Leslie, STATisfy Analytics, San Diego, CA

ABSTRACT

SAS® Enterprise Guide

® allows users to import and display data quicker and easier than ever. The Import Data

wizard contains multiple options to transform Excel spreadsheets into clean SAS data sets which can then be displayed as charts, tables and graphs with the use of several available Task wizards. Topics covered in this paper include navigating Enterprise Guide menus, importing Excel spreadsheets using the Import Data wizard, summarizing data sets with Task wizards, and using the Report Layout tool to create a PDF of your final output. US Census and publicly available real estate data on Las Vegas are used to demonstrate these effective Enterprise Guide features.

INTRODUCTION

This paper provides two examples of using the Import Data wizard to import Excel spreadsheets as SAS data sets. The first example is a rather simple example using a clean spreadsheet. Since many spreadsheets are not created for the purpose of using within SAS, the next example presents hints for how to import spreadsheets with multiple header rows and how to format variable during an import. Once a SAS data set is created, a logical next step is to profile the data set. This is easily done with task wizards that can display data concisely with charts and graphs. Subsequently, content created by task wizards is easily assembled using the Report Builder function which allows exporting SAS reports as PDF or HTML files. This paper is intended for SAS users with less experience with Enterprise Guide or those in need of handy tips on automating code and processes within an Enterprise Guide project.

QUICK REVIEW OF THE ENTERPRISE GUIDE INTERFACE

This section is a brief overview of the Enterprise Guide interface. For those familiar with the look of Enterprise Guide, please look forward to the next sections of this paper.

At first glance, the application looks very menu driven and can be unpleasant to traditional SAS programmers. It took me a while to reconcile the log and output windows. After time, I came to realize that the interface has many more features than the Display Manager seen in SAS. The key to getting accustomed to Enterprise Guide is learning how to work with process flows.

First, all work is organized in one file called a Project with the file extension “.epg”. A sample project is shown below. All code, data, log and output are contained in the project and represented as Nodes (the icons) shown in the Process Flow window below. So the process flow represents your desktop that charts all your work. I find this

process flow window useful because projects can be broken into steps. For example, instead of 1000 lines of code in one program that don’t have natural breaks you can have 4 or 5 programs as steps within a process flow. This is explained later in the paper. The Process Flow and Project Tree windows give programmers an easy view of your

entire project.

Display 1. SAS Enterprise Guide Interface

Page 2: Importing and Displaying Data Using SAS Enterprise … and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued 2 CHANGING SAS ENTERPRISE GUIDE SETTINGS If you

Importing and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued

2

CHANGING SAS ENTERPRISE GUIDE SETTINGS

If you would like to change the Enterprise Guide environment such as Project Tree views and outputted results, go to the Tools Options. The most relevant option for this paper is the Results Results General option, where you

change the format of your output. You can choose to generate SAS Report, HTML, PDF, RTF, and/or text files.

Display 2. Changing your Environment with the Options Menu

EXAMPLE 1: STANDARD IMPORT OF EXCEL SPREADSHEET

The first example demonstrates a fairly simple import of an Excel spreadsheet that is shipped with Enterprise Guide. Display 3 shows this spreadsheet, as_products.xls, has 61 observations and 6 variables. It contains fabricated data on cost, price and type of products.

Display 3. View of the as_products spreadsheet

As you can see, this is a fairly clean file. It doesn’t have any data entry errors, missing values or blank rows. Importing this file into SAS can be done by starting the Import Data wizard by using the menus File Import Data

and browse to the location of the file.

Page 3: Importing and Displaying Data Using SAS Enterprise … and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued 2 CHANGING SAS ENTERPRISE GUIDE SETTINGS If you

Importing and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued

3

The first step of the wizard is lets you name the server, library and of the data set for output. The default library is SASUSER.

Then you select the data range and some options. It’s useful to check the 2 options in this window.

The third step in the wizard allows you to define field attributes. You can change field names, formats, lengths. This may take some back and forth but becomes very useful for future imports.

The last step asks if you would like to embed the data in the DATA step. Recommend not selecting this if you have a large file.

Page 4: Importing and Displaying Data Using SAS Enterprise … and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued 2 CHANGING SAS ENTERPRISE GUIDE SETTINGS If you

Importing and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued

4

Here’s the result of the final data set.

Display 4. Imported as_products Data Set

Here’s the code generated after the Import Data wizard is complete. Notice SAS EG converts the Excel file to a text file and imports using a DATA step with INFILE statement. When importing the EG Import Data Task creates a temporary text file as the source file for the import. If you have SAS/ACCESS to PC Files product, check the box on the Import Data Wizard.

/* --------------------------------------------------------------------

Code generated by a SAS task

Generated on Saturday, September 07, 2013 at 8:52:22 AM

By task: Import Data

Source file: C:\Users\Richard\Dropbox\SAS Presentations\WUSS

2013\EG\as_products.xls

Server: Local File System

Output data: SASUSER.as_products

Server: Local

-------------------------------------------------------------------- */

/* --------------------------------------------------------------------

This DATA step reads the data values from a temporary text file

created by the Import Data task. The values within the temporary

text file were extracted from the Excel source file.

-------------------------------------------------------------------- */

DATA SASUSER.as_products;

LENGTH

SUPPLIER_ID $ 3

PRODUCT_CODE $ 4

DESCRIPTION $ 26

COST 8

PRICE 8

PRODUCT_TYPE $ 11 ;

FORMAT

SUPPLIER_ID $CHAR3.

PRODUCT_CODE $CHAR4.

DESCRIPTION $CHAR26.

COST DOLLAR20.2

PRICE DOLLAR20.2

PRODUCT_TYPE $CHAR11. ;

INFORMAT

SUPPLIER_ID $CHAR3.

PRODUCT_CODE $CHAR4.

DESCRIPTION $CHAR26.

COST DOLLAR20.

PRICE DOLLAR20.

Page 5: Importing and Displaying Data Using SAS Enterprise … and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued 2 CHANGING SAS ENTERPRISE GUIDE SETTINGS If you

Importing and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued

5

PRODUCT_TYPE $CHAR11. ;

INFILE 'C:\Users\Richard\AppData\Local\Temp\SEG5732\as_products-

ecce9427dbc944a580692544e184c32f.txt'

LRECL=56

ENCODING="WLATIN1"

TERMSTR=CRLF

DLM='7F'x

MISSOVER

DSD ;

INPUT

SUPPLIER_ID : $CHAR3.

PRODUCT_CODE : $CHAR4.

DESCRIPTION : $CHAR26.

COST : BEST32.

PRICE : BEST32.

PRODUCT_TYPE : $CHAR11. ;

RUN;

DISPLAYING DATA WITH TASK WIZARDS

Once creating the SAS data set, you can profile or describe the data with one of many Tasks (e.g., table, bar graph, pie chart) available in SAS EG. Graphs and reports that are seemingly tedious and time consuming to code can be created with a few steps in a wizard. Also, you are not stuck with one particular result after the wizard. That is, you can use the code generated by Enterprise Guide (explained later in this section).Using the Context tabs at the top of the data set to create a pie chart. Here’s a view of the data set and drop down menu for graphing the data set.

Display 5. Launching a Pie Chart Task

Page 6: Importing and Displaying Data Using SAS Enterprise … and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued 2 CHANGING SAS ENTERPRISE GUIDE SETTINGS If you

Importing and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued

6

After going through the wizard, here are the results of running the Pie Chart task wizard.

Output 1. Result of Pie Chart Task

Task wizards run code very quickly without writing the code. But you can add and change code when needed. After running a task wizard, the code that Enterprise Guide creates is viewable and modifiable. I find this easy to copy this code into a new program and then make any necessary modifications. This allows you to leverage Enterprise Guide to write the code and learn additional SAS syntax. The window below shows the PROC GCHART code generated when running the Wizard. The code is created and accessible to you from the Code tab in the Context Menu. This feature (new starting with version 4.2) allows users to modify and re-run tasks quickly and easily. In the project explorer window, selecting the tab opens the code for viewing. You can now edit the code and rerun.

Display 6. Modifying Task-Generated Code to Re-Run a Pie Chart Task

Page 7: Importing and Displaying Data Using SAS Enterprise … and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued 2 CHANGING SAS ENTERPRISE GUIDE SETTINGS If you

Importing and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued

7

EXAMPLE 2: IMPORTING A LESS THAN CLEAN SPREADSHEET

Not all spreadsheets are ready for perfect conversion into a SAS data set. Files may contain headers, variety of formats, footnotes and other data that is not wanted in your final data set. This example shows functions of the Import Data wizard that help you select the data range, rows and columns plus change field attributes. Many of these features are well documented in Tricia Aanderud’s Business Intelligence blog and Maria Shapiro’s paper listed in the references section at the end of the paper.

For this example, data from Zillow, a home and real estate marketplace, containing the monthly median sales price of single family homes in Las Vegas is imported. After downloading a multi-tab Excel sheet from the website, the Import Data wizard is used to import select data. The next screens shots show many other features of the Import Data

wizard, namely selecting ranges of cells in Excel and changing data field attributes. As shown in the previous examples, Step 1 ask you to specify the data source and output parameters of your import.

Step 2 selects the “Transpose” worksheet and asks SAS to rename columns to comply with SAS naming conventions.

Step 3 allows you to deselect data fields (useful if many data fields are not needed), rename/label variables (customize your variables), and set length, formats of variables. In this example, a data field in Excel, “Month year”, was renamed to “month_year” to fit with SAS naming conventions and more importantly, the Output format was changed to MONYY7.

Page 8: Importing and Displaying Data Using SAS Enterprise … and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued 2 CHANGING SAS ENTERPRISE GUIDE SETTINGS If you

Importing and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued

8

Step 4 of the wizard allows for advanced options (not used for this example).

Page 9: Importing and Displaying Data Using SAS Enterprise … and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued 2 CHANGING SAS ENTERPRISE GUIDE SETTINGS If you

Importing and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued

9

Now with the resulting data set you can graph the monthly median sales price of Las Vegas single family homes for the last decade. From the Context menu you can select the List Data drop down menu.

Results of Line Plot Task wizard. During the wizard process, you can add titles, adjust axes, and format lines. Las Vegas was hit hard with housing bubble and the recent Great Recession.

Page 10: Importing and Displaying Data Using SAS Enterprise … and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued 2 CHANGING SAS ENTERPRISE GUIDE SETTINGS If you

Importing and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued

10

To complete this example data obtained from the US Census Bureau website is imported. The file includes high-level facts on Nevada and the United States (shown for comparison). Here’s a view of the data set. Notice it’s rather messy with blank rows and footnotes.

As shown in the prior example, start the Import Data wizard by using File Import Data and browse to the location

of the spreadsheet.

Now from this new data set, you can launch a List Report from the Context Menu. This is shown below.

Page 11: Importing and Displaying Data Using SAS Enterprise … and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued 2 CHANGING SAS ENTERPRISE GUIDE SETTINGS If you

Importing and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued

11

The results are shown below. The wizard has options for titles and showing row numbers, etc.

BUILDING A REPORT FROM EXISTING SAS ITEMS AND TASKS

This section of the paper describes the SAS report building function with an example of how to build a report from SAS tasks and items. Most projects contain many output items (tables, graphs, charts, etc.) that all need to be assembled for a final report. Building a report with the use of the Report Layout function is a straightforward method

for creating an end result of all your work. All tasks can be compiled into a single report and exported to a SAS Report, PDF, RTF, or HTML document.

To create a new report, you can use one of 3 methods,

1. Select File New Report

2. Right-click on the Process Flow area and select New Report

3. Right-click on a SAS Report item and select Create Report

With any of the three methods above, a New Report window will pop open with the SAS items that you have created in your project (i.e., the bar charts and graphs, tables shown earlier in this paper). Please keep in mind the SAS item results will only appear if they were created in the SAS Report format. That is, before running tasks, make sure that SAS Report box is checked from Tools Options Results Results General window.

Page 12: Importing and Displaying Data Using SAS Enterprise … and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued 2 CHANGING SAS ENTERPRISE GUIDE SETTINGS If you

Importing and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued

12

Continuing from data used in the examples above; a SAS report is created from tasks previously run (List Data and Line Plot). Once the report is created, the available SAS items in the left pane of the window can be dragged over to the Report Layout pane of the window to be organized (as seen in the window below). You can also add text and

images to the report in this window.

Adding text and images are done using the buttons that open windows that you can easily navigate. You can also add links to web sites or files. Edit text by double-clicking on the text in the report or by selecting the text and pressing the space bar.

Available images to add to your report include: BMP, JPG or GIF. Resizing images can be done by either dragging the handles (the small squares see below) or selecting the image and pressing ALT and the left, right, up, and down arrow keys. Additional features include exporting the report as a step in the project or directly. You can also email SAS Reports for others to view, change, or add.

You can preview any item in the Report Layout area with the Show Preview button. This is helpful because you

don’t always remember the contents of all the SAS items. Previewing gives a quick way to see what items will be placed where. This does take some trial and error to get the items in the desired locations.

In this example, header and footer text is added to show where these additions will be placed. The final document is a PDF file complete with text, table and header/footer. The first page looks like this.

Page 13: Importing and Displaying Data Using SAS Enterprise … and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued 2 CHANGING SAS ENTERPRISE GUIDE SETTINGS If you

Importing and Displaying Data Using SAS® Enterprise Guide®: Las Vegas Style, continued

13

SAS® ENTERPRISE GUIDE® VERSIONS 4.3, 5.1 AND 6.1

The analyses and work shown in this paper was done in Enterprise Guide version 4.2. More recent versions, 4.3, 5.1 and 6.1 include additional features. The most noteworthy new features are a new program editor with autocomplete and integrated syntax help. These features complete and show syntax while you are coding (e.g., typing PROC in the program editor will create a pop-up window that lists all available procedures for you to choose from). Visit the What's New in Enterprise Guide 5.1 website for details.

CONCLUSION

SAS® Enterprise Guide

® offers quick and easy ways to import and display data. The Import Data wizard contains

multiple options to transform Excel spreadsheets into clean SAS data sets which can then be displayed by multiple Task wizards. This paper and presentation describes the Import Data wizard to import Excel spreadsheets, Task wizards to display data concisely with charts and graphs, and Report Builder features to create a PDF of final output.

REFERENCES

Aanderud, Tricia. “SAS Enterprise Guide: Import Odd Spreadsheet Data”. BI Notes webpage. Accessed September 9, 2013. Available at http://www.bi-notes.com/2012/05/sas-enterprise-guide-import-excel/

Shapiro, Maria and Lafler, Kirk Paul. “Using SAS® Enterprise Guide® to Coax Your Excel Data In To SAS®”. Proceedings of the SAS Global Forum 2012 Conference. Orlando, FL. Paper 289-2012. http://support.sas.com/resources/papers/proceedings12/289-2012.pdf

Getting Started with SAS Enterprise Guide – free learning tutorial available at http://support.sas.com/documentation/onlinedoc/guide/tut42/en/menu.htm

RECOMMENDED READING

What’s New in SAS Enterprise Guide 5.1 http://support.sas.com/documentation/cdl/en/whatsnew/64209/HTML/default/viewer.htm#egwhatsnew51.htm

Little SAS Book for Enterprise Guide 4.2 – By Susan J. Slaughter, Lora D. Delwiche, http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=61861

SAS Fact Sheet, Accessed 0/09/13 http://www.sas.com/technologies/bi/query_reporting/guide/factsheet.pdf

CONTACT INFORMATION

Your comments and questions are valued and encouraged. Contact the author at:

Name: R. Scott Leslie Enterprise: STATisfy Analytics Address: 11675 Castile Way City, State ZIP: San Diego, CA 92128 E-mail: [email protected]

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.