SAS Enterprise Guide
SAS Enterprise Guide
Hands-on Workshops
Paper 166-2011 SAS Enterprise Guide 4.3: Finally a Programmers Tool Marje Fecht, Prowerk Consulting, Canada and USA Rupinder Dhillon, Dhillon Consulting, Toronto, ON, Canada
ABSTRACT
Have you been programming in SAS for a while and just arent sure h ow Enterprise Guide can help you? It isnt just a pretty face! This presentation demonstrates how SAS programmers can use SAS Enterprise Guide 4.3 as their primary interface to SAS while maintaining the flexibility of writing their own customized code. We explore: navigating the views and menus using Enterprise Guide to access your existing programs and enhance processing exploiting the enhanced development environment including syntax completion and built-in function help utilizing Code Analyzer, Report Builder, and Document Builder adding Project Parameters and dynamic parameters to generalize the usability of programs and processes leveraging built-in capabilities available in SAS Enterprise Guide to further enhance the information you deliver. Audience: SAS users who understand the basics of SAS programming and want to learn how to use Enterprise Guide. It is also appropriate for users of earlier versions of Enterprise Guide who would like to try out the enhanced features available in Enterprise Guide 4.3.
INTRODUCTION
This presentation is designed as a Hands-On Workshop, where the participants follow along and step through the usage and features of SAS Enterprise Guide. This paper follows a similar format.
SAS
Project
-1-
Hands-on Workshops
GETTING STARTED
The first time you open Enterprise Guide, you will see the Welcome to SAS Enterprise Guide Screen.
This screen gives you the option of launching the Enterprise Guide tutorial or working with new or existing programs, data, or projects. If you do not want this to be your default screen when you open Enterprise Guide, you can check the box labeled Dont show this window again. Close the window, to be taken to the default view of Enterprise Guide. The main menu (menu bar at top of screen) allows you to access the various tasks and views that are available to you. Although you may also access the tasks and views through tabs and shortcut buttons, the main menu organizes them into logical categories, making them easy to find.
As SAS Programmers, you know that the tasks you are expected to perform are seldom simple. More often than not, there are a series of SAS programs that you run in a sequence, with different types of output directed to different locations, along with all the intermediate and final SAS datasets that are generated. Enterprise Guide provides a mechanism to organize your work by allowing you to group sequences of tasks, data items and results into Projects. All of the code and tasks that you run within an Enterprise Guide session are part of your
Hands-on Workshops
active Project and are each displayed as separate nodes within the Process Flow view and Project Tree view. These nodes can be linked and organized in a logical sequence to form a Process Flow. You can save your Process Flow as a part of a Project; and anytime the project is opened the same sequence of tasks can be easily executed. This helps you and your organization distribute and share information easily. The Process Flow view is used to display all of the task, data and code nodes that make up your Process Flow. There are a number of ways that you can access your Process Flow view. From the main menu, select View Process Flow. You can also select F4 or click the Process Flow tool in the menu bar. Once you begin building a flow, you will notice that the Process Flow view also displays the connections between your work components. Again, this allows you to see and visually inspect the organization of tasks, code and data associated with a Project. You may prefer the Project Tree view (in the upper left of the above screen), which provides a more traditional Windows Explorer hierarchical view of your projects. Select View Project Tree from the main menu to open the Project Tree view. Note that the Project Tree view does not display the flow (connection) within your projects.
Hands-on Workshops
To view the process flow and then run the program, select the Process Flow shortcut on the menu bar. Notice that a code node, Program_1 is added to your Process Flow and Project Tree views. Notice the shortcut symbol with the code node, reminding you that this is a pointer to the locally stored version of Program_1
run the program by selecting Run On Local from the POP MENU in the code node, OR by selecting Run from the context menu in the Process Flow view.
In this instance, we are running the SAS program using the Local version of SAS. You can change your connection settings to switch from a local SAS instance to a server instance or to switch from one server to another in the Administration panel of your Options screen ( Tools Options Administration). The remainder of the examples in this paper assume that we are running on the Local Server. When the program completes running, the Process Flow view shows the components created by program_1, as additional nodes.
Helpful Hint: To change the type of Results generated by a code node or task, right click on the node and select properties. Under the Results, click the checkbox beside the type of output you want to generate.
Hands-on Workshops
In the above window, notice that the only symbol attached to the code node is the shortcut symbol. However, if your program resulted in an error or warning, you would see an additional symbol such as an exclamation point. When you rest your mouse over the code node, in addition to providing basic information about your program, you may also be informed to check for warnings or errors. To review the log messages, select Program_1 in the Context Menu, and then select the Log tab. As always, carefully check your log for any messages that require attention. Notice the Data and Results tabs that are also available.
Helpful Hint: If you would like your SAS Log to open automatically when you have an error, check the Display SAS Log when Errors Occur option in your Results settings.
Helpful Hint: If you received an error or warning message about unsupported device ACTIVEX for PDF destination, you can either Add options dev = actximg; to your SAS code prior to the ods pdf statement, or, Change the default graphics driver from ActiveX to ActXImg using Tools Options Results Graph and select Graph Format of ActiveX image (SAS V9) Since our example program produces an Excel Spreadsheet report and a PDF report as output, you can use your normal process for opening and reviewing the results (such as Windows Explorer). Or, you can select the results from the Process Flow view to view the output. Each type of generated result will display as its own result node in your Process Flow view. Further, if you select Program_1 from the Context Menu, you will see the program, log, and each output displaying in a separate tab, as below.
Note that when you select output such as an excel spreadsheet, you will be prompted about downloading the results.
Hands-on Workshops
Everyone has different preferences about how Enterprise Guide windows should work, and Enterprise Guide provides the flexibility for you to create a work space that works best for you. For example, Enterprise Guide windows can be docked and undocked resized to make best use of the real estate hidden so that you only display what you need and use opened as new horizontal or vertical tabs easily reopened using the main menu or shortcut buttons. Helpful Hint: Unhappy with your window changes? Select the Restore Window Layout button in the Options window.
Hands-on Workshops
Syntax Suggestion / Autocomplete when coding When you enter the first 2 letters of a SAS keyword, a list will pop-up displaying possible keywords you can select from. This includes available PROC options.
NOTE: Syntax suggestions INCLUDE user-defined Macro Variables and Macro names as long as they are defined through the active program. Macros and Macro Variables created through an autoexec are not included.
Parenthesis Matching very helpful for debugging macros, complicated expressions, and SQL code. This also works for brackets ( [ ] ) and braces ( { } ).
While all of these goodies are handy, they may also annoy you if you do not want help. How do you turn these features off? To turn any of the autocomplete features off, go to Tools Options SAS Program Editor Options.
Hands-on Workshops
Helpful Hint: If you would like to run just a section of the code, highlight and submit just like you do in the SAS Display Manager Editors.
Hands-on Workshops
Helpful Hint: The output tab is always open. To close a dataset that Enterprise Guide sees as open, right click on the dataset and select Close Data.
Notice that there are now tabs for the input data, code, log, and results. Additionally, the Context Menu allows you to easily Modify Task if you have changes to make.
Hands-on Workshops
Helpful Hint: The Task Status Window shows you the status of the code or task you are running. If you are running large SAS programs, the Task Status will tell you which task or Procedure is currently running. You can open your Task status view from your Main menu. Select View Task Status. Each of the built-in tasks will generate SAS code as you step through the Task Panes. This serves as a great way to learn how to code new SAS Procedures since the syntax is available to view and edit.
CUSTOMIZING THE GRAPH FORMAT
By default, graphs are generated as interactive ActiveX graphs, which are cool but can use up a lot of system resources. You may prefer or require a more static format such as HTML or JPEG. You can easily change the default in the Graph Results settings of Options. Select Tools Options Results Graphs and select a different format from the drop down list.
There are lots of features in Enterprise Guide that make graphs easy to produce. You should explore the variety of ways to visualize your data, including the Tile Chart which allows you to display magnitudes by size and colour. In this Tile Chart example, the size of the rectangles represent the number of stores in each region; the bigger the rectangle, the more stores in the region. The colour represents the Sales. The colour legend shows that the darker the green, the higher the dollar value of the sales. A Tile chart can be created by launching the Graph Tile Chart Task. Select Tasks Graphs Tile Chart
10
Hands-on Workshops
Enterprise Guide also has a Built-in task that allows you to produce Maps. These require specific mapping data and will not be discussed in this paper. Other features include: Context based menu bar when looking at Graph Results o Allow you to quickly modify the graph task o Makes it easy to refresh the graph
Each graph type has a detailed wizard, including options to control the graph output You can save your graph task preferences in a template that can be reused so that you can define appearance attributes, headers, footers etc only once and save them in a template.
Helpful Hint: To remove a link between tasks or Code nodes, right click anywhere on the joining arrow and select Delete. This will only delete the linkage, not the code nodes.
11
Hands-on Workshops
Youll notice that a separate log node is generated for each code node. By turning on Project Logging, you can easily tell Enterprise Guide that youd like a single SAS log to be generated for all of the tasks and code nodes in your Project. This single Project Log will be created in addition to the individual logs created for each task or code node.
Helpful Hint: If Project Logging is turned on, the log represents a running log of the entire project. To turn on the Project Logging, select Project Log in the Context Menu of the Process Flow, and then select Turn On.
Helpful Hint: When working with several tasks and code nodes in a single project, you can export all of the generated SAS code as a single .sas file by selecting File Export Export All Code.. Enterprise Guide will scan through your project to find all executable code and save it to a single .sas file. You can select export all the code or select only parts of your project.
At this point, save the Project so it is available for another day. Select File Save Project As Local Computer Navigate to the file path where you would like to save your project. Enter a name for your Project, and Click ok. The next time you open your saved project; you will see the code nodes and links that you defined in this session. Note that any temporary work datasets that you may have created in your session will not be saved with your project. You can easily recreate the work datasets by re-running the project the next time you open it.
12
Hands-on Workshops
A new flow is added to your project called Program_1 (defaults to the name of your program node). Note that the Code Analyzer did not run the code and produce results.
Run the new flow by right clicking on the starting dataset (SASHELP.SHOES) and selecting Run Branch from SASHELP.SHOES.
13
Hands-on Workshops
Helpful Hint: When working with multiple flows, its a good idea to rename the flows to something meaningful. Right click on the Process flow in the Project Tree and select Rename.
14
Hands-on Workshops
Step 3 allows you to define totals for your report. In the Select Totals window, select Sales Select Edit to control how subtotals are handled Select Totals by Region Select OK to return to Step 3 window Notice that the visual of the sample report shows SALES totaled and also shows region subtotals. Click Next to move to Step 4.
In the Step 4 window, provide titles and footnotes, and select Finish The report displays, along with the Context Menu Bar enabling you to easily make changes and view the Log, Code, Input Data, and Results.
Select the Code tab and review the generated code. Notice it is similar to the PROC REPORT code used in Program_1.sas.
15
Hands-on Workshops
Then click Insert Text and add the text This is a Shoes Sales Report for January 2010. Change the font of the text to 16 pt and rearrange the report layout to match the below layout.
Once the report is generated, Click Page View and change the layout to Landscape. To export the report as PDF, Click Export in the context based menu bar and select Export as Step in Project. The Report is highlighted. Click Next. Select Portable Document Format (.pdf) and specify the Location to save Report, and choose an appropriate location. Under Output Options, Uncheck Overwrite Existing output. Select Next Finish.
16
Hands-on Workshops
Select the Prompt Type and Values tab In the Prompt Type dropdown, select Text In the Method for populating Prompt dropdown, select User selects values from a static list Select Get Values to identify the source of the static list Select Browse to load values from SASHELP.SHOES Servers Local Libraries SASHELP Shoes From the columns dropdown, in the Unformatted Values section, select Region From the columns dropdown, in the Formatted Values section, select Region In the Available Values section, under the Browse tab, select Get Values Move all of the values over to the Selected Values window Select OK In the List of Values, designate Canada as the Default value and Select OK .
RegionID now appears in the Prompt Manager view and is available to use as a prompt. Now we need to modify the program to accept prompts. From the Process Flow window: Right click on the Program_1 Code Node and select Properties From the Properties window, select Prompts and Click Add Select RegionID and click OK Click OK again to close the Program node Properties window . Now, modify the program so that the prompts control the data selected. Open the Program_1 code node ADD where Region = ®ionID in the Ex_Shoes_Data data step Save the changes to Program_1 Right click on the Program_1 code node, Select Run Branch From Program_1. When prompted to select a Region, select Asia from the drop down list. Click Run. If we take a look at the Ex_Shoes_Data dataset and subsequent graph and report, only observations with a regionID of Asia are included.
17
Hands-on Workshops
Instead of forcing just a single selection, what if you wanted to add flexibility and thus enable multiple selections from the list? We need to alter the prompt we created so the user can select a list of values. Select the RegionID prompt from the Prompt Manager Window and click Edit Since you are altering a prompt that an existing program uses, you will be asked to confirm. Select Yes
Under the Prompt Type and Values tab, select Multiple Values from the Number of values dropdown Click OK.
Right Click on the Program_1 node to open the code Change where region = ®ionID to where Region IN ( ®ionID ); Save the changes to your Program_1 code node. Right click on the Program_1 code node, Select Run Branch From Program_1. Move Africa, Canada and Eastern Europe over to the Selected window and then select Run.
18
Hands-on Workshops
OK ENTERPRISE GUIDE REALLY WILL HANDLE MY NEEDS BUT HOW CAN I OFFLOAD SOME OF MY WORK (OR DO MORE WORK IN LESS TIME)?
For most SAS programmers, it is a rare occurrence to write a program that is never used again. More typically, you write programs that either run in production, or that are rerun with different input (prompts) on a regular basis. Furthermore, YOU are not always the person that runs the job after it is written. Someone else may be responsible for providing input prompts (changes) and running your code when results are needed. With this in mind, we explore how you can easily set up your code so that others can access and get the results they need. You will do this by creating a Stored Process. A Stored Process is a SAS program that is typically located on a central server (ie: available to multiple users across multiple clients) so that users can run the SAS Code but cant change the SAS code. Designed properly, the Stored Process enables user input to maximize the applicability of the code. For example, you can embed business rules and logic so that everyone is creating consistent results have change control around any coding updates can make your code available to more people can provide the users with input prompt choices to take care of minor tweaks in the requirements can add cascading prompts to make User input easier and more flexible.
For more information on creating and using Stored Processes, refer to the SAS Online Documentation or to the many SAS Global Forum papers on the topic.
19
Hands-on Workshops
When you submit a task or a program from Enterprise Guide in a Server Environment, the following will occur: 1. 2. 3. 4. Your Enterprise Guide session connects to an Object Spawner. You connect to the metadata server through the Object Spawner. The metadata server verifies your credentials (password and user ID). Once credentials are verified, the Object Spawner starts up a dedicated SAS session for you on the SAS Application Server. It also creates a temporary Work space library for you that persists as long as your Enterprise Guide session is connected. If your program or SAS Task uses data that is on a Database (eg. Oracle, DB2, Netezza), the SAS Application Server will connect to the database server.
DATA
Object Spawner
1:
` EG and MS Office
4: Access Data
There are several important things to keep in mind when running Enterprise Guide in a server environment. First off, as we mentioned above, when you first launch Enterprise Guide, a temporary workspace library is created on the server that will be dedicated to you Enterprise Guide. This is where your WORK library is saved. When you disconnect your Enterprise Guide session, that temporary workspace location is deleted. As you keep working and creating more and more temporary datasets in your work library, the workspace location dedicated to your session is getting bigger and bigger. You may not need many of those datasets anymore but until you delete them or disconnect your EG session, youre still using up that space. Its therefore best practice to either delete any large datasets that youre no longer using, or to disconnect your Enterprise Guide session once your work is finished so the space can be released.
WORK LIBRARY
Object Spawner
` EG and MS Office
Secondly, you may find that when you run your SAS programs through Enterprise Guide in a server environment, things sometimes seem to take longer to run. Most SAS programmers will assume that Enterprise Guide is slowing down their work but more often than not, it is the movement of data that is creating the bottleneck. When data resides on a database for example, it has to move from the database, to the SAS server and then to Enterprise Guide. These extra steps can add to how long it takes to run your jobs when youre dealing with large amounts of da ta. In order to minimize the amount of data that is being moved, you want to make sure that the Database is doing as much of the
20
Hands-on Workshops
work as possible and then passing only the results back to SAS and the Enterprise Guide session. This can be done by using indexes, partitions and keys that exist on the database tables. It can also be done by taking advantage of SAS/Access engines. SAS/Access engines are designed to translate many SAS functions into functions that can be understood and performed by the Database. For example, the SAS/Access engine for Oracle will translate the SAS Datetime function into the SYSDATE function in Oracle. If a SAS query command cant be translated into a Database command, the database is going to pass back ALL of the data to the SAS server so that it can process the command. This is what is going to slow down your performance causing longer query times, excessive server usage and slower server response for other users. Therefore, when writing queries against large databases, wherever possible, you want to ensure that joins, filters and SAS functions are passed to the database to perform. Finally, there are a number of SAS coding techniques that are either not well suited for use in a Server Environment, or will not work at all in a Server Environment. Writing to or reading from your local C: drive is not going to work. The server will not recognize your C: drive as a valid location. Workaround: You can use the Import and Export Wizard to access files on your PC. You can also use the Upload and Download tasks to read and write SAS datasets to your local computer. Using ENDSAS or ERRORABEND will disconnect you from the server completely. Your Work library and log are lost. Workaround: Use Conditional Flows to build error handling into your projects SAS/AF is not available. Workaround: Use Project Prompts and macros in your code to get interactive input from your users. DDE (Dynamic Data Exchange) will not work using Enterprise Guide in a Server Environment. Workaround: Using the Excel Libname engine provides flexibility when working with Excel spreadsheets and is easier to use than DDE. X Command and SYSTASK are disabled by default. Workaround: Might be a long shot, but plead your case to your Server Administrator to have this enabled if this is truly needed. Rsubmit commands are no longer needed since youve already established the server connection when you logged into Enterprise Guide. While a Server Environment will introduce differences that are going to affect how you create your SAS code in Enterprise Guide, dont panic remember, under the covers its still SAS.
I WANT TO IMPRESS MY CO-WORKERS HOW ABOUT SOME USEFUL TIPS AND TRICKS?
TIP 1: USE ORDERED LISTS
What if we have 3 SAS jobs that wed like to run, one after the other? Or perhaps we have some processes that wed like to submit at the end of the day so we can have the results ready the next morning. In this case, we dont really want to build a project; we want to be able to submit a list of SAS j obs or tasks that we want Enterprise Guide to run. This is where we would Create an Ordered List. The Ordered List task in Enterprise Guide allows you to specify a list and sequence of tasks and jobs that you want Enterprise Guide to run. To create an ordered list, go to File New Ordered List.
TIP 2: SHARING YOUR PROJECT WITH OTHERS
If you have notes embedded in your projects, you can email those results to yourself or others in your organization. This is a great way to let people know that a report is ready to view or data has been refreshed. When you combine notes with conditional process flows, you can alert others when your project has encountered some unexpected data or hasnt completed successfully. Notes are also a great way to document important details about your process and keep them embedded in your project. You can use notes to list the inputs used on your process or the results that are produced. You can also use them to provide instructions on how and when the project should run, To add a note to your project, select File New Note. The linking feature to attach the note to a specific task, program or results node.
21
Hands-on Workshops
How many times have you spent an afternoon on a SAS Project and j ust when youre almost done and ready to save it, the power goes out or youve inadvertently kicked the plug. Your EG session is gone, along with an afternoons worth of work. First things first ENABLE PROJECT RECOVERY. This new feature autosaves your project at set intervals and you can specify how often you want the Project to be saved. To enable project recovery, go to Tools Options Project Recovery Check Enable Project Recovery.
TIP 4: AVOID OPENING LARGE DATA UNLESS YOU HAVE TO
By default, when data is added to your project, Enterprise Guide will open that data in a new Data tab. This is fine and even helpful when were working with small SAS Datasets however, this can bring Enterprise Guide to a stand still when we find ourselves working with large amounts of data in a database. As we described above, all of the data has to move between the database server, to the SAS Server to your Enterprise Guide session. To make the data available to your project but avoid opening it automatically: Select Tools Options Data UNCHECK Automatically open data when added to project.
TIP 5: EXPORT YOUR PROJECT TASKS AS SAS CODE
Once youve completed all of your exploratory work, you may end up with a mix of tasks and custom program nodes. You can save all of them or a subset of them as a single SAS file which you may then want to run in Batch mode. When exporting the Code in your project, Enterprise Guide scans through your project and assembles all of the SAS code that was either generated by a task or was written in a custom program node. You can then select which parts of the project you want to include in the final SAS file and the order in which the SAS code should appear. To export all of parts of your project to a SAS File, select File Export Export all Code in Project
TIP 6: FORMATTING CODE EASILY
Do you inherit code that is poorly formatted? There is relief!! Open the program node, right click and select Format Code
Helpful Hint: To specify formatting preferences, override the options in Tools Options SAS Programs Editor Options Indenter tab. This allows you to set the spacing on indents and select which statements signal a new line.
You may be familiar with using an autoexec.sas file to enable setting up your SAS environment at startup. It works in Enterprise Guide too! Just add a Process Flow to your Project called AUTOEXEC. Enterprise Guide will run the flow when you open the project. This is handy for setting up libraries, controlling options, etc.
22
Hands-on Workshops
Enterprise Guide provides split screen options that enable you to explore tasks, programs and data side-by-side. Option 1: Split screen to view different sections of same tab Right click on the view you are looking at Select Split Select Stacked, Side by Side or Both Option 2: Split screen to view different tabs Select View from the Main Menu Click Workspace layout Select Stacked or side by side. Each view will have a drop down at the top left corner that allows you to select what you want to view.
CONCLUSION
Enterprise Guide provides a powerful environment and toolset for end-to-end information delivery. As a SAS programmer, you can easily begin taking advantage of Enterprise Guide to provide a flexible reporting and analytics environment to meet your organizations business needs.
RECOMMENDED READING
To gain a more complete understanding of Enterprise Guide the authors recommend the following
Getting Started with SAS Enterprise Guide free learning tutorial available at
http://support.sas.com/documentation/onlinedoc/guide/tut43/en/ 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
CONTACT INFORMATION
Your comments and questions are valued and encouraged. Contact the authors at: Marje Fecht Prowerk Consulting [email protected] www.prowerk.com 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.
23
Hands-on Workshops
APPENDIX PROGRAMS
PROGRAM_1.SAS /*******************************************************************************/ /* /* Example Program 1 - Output Excel Spreadsheet and PDF w/ Shoes data */ Note: multiple statements on a line to demonstrate new EG 4.3 feature */
/*******************************************************************************/ data Ex_Shoes_Data; set sashelp.shoes; AverageSalesPerStore = sales / stores; label AverageSalesPerStore = 'Average Sales Per Store'; format AverageSalesPerStore dollar12.2; run; ods listing close; ods tagsets.ExcelXP path = 'C:\HOW\Fecht' file='EG Basic_Report.xls' style=statdoc options (sheet_name = 'Example 1' autofilter = 'All' ); title "Simple SAS Code Example 1"; frozen_headers = 'Yes'
proc print data=Ex_Shoes_Data noobs label ; run; ods tagsets.ExcelXP close; ods listing;
/*******************************************************************/ /* Create PDF Report */ /*******************************************************************/ ods listing close; ods pdf file = 'C:\HOW\Fecht\EG Shoes_Report.pdf'; proc report data = Ex_Shoes_Data; column ("Location" (Region Subsidiary Stores)) Product ("Sales" ; define region / order "Region"; define Subsidiary / order "Subsidiary"; define Stores / display "Number of Stores"; define Product / display "Product"; define Sales / Sum "Sales"; define AverageSalesPerStore / Sum "Avg Sales per Store"; break after region / summarize; run; ods pdf close; ods listing; rbreak after / summarize; (Sales AverageSalesPerStore))
24