web view“experienced” dogs, new tricks: sas® enterprise guide for sas® display...

13
“Experienced” Dogs, New Tricks: SAS ® Enterprise Guide for SAS ® Display Manager Programmers Randall Cates, Principal Technical Training Specialist SAS Institute Inc., St. Louis, MO ABSTRACT SAS ® has been around since 1976, and programmers learned how to work with SAS code using the old standard SAS ® Display Manager. Now SAS ® Enterprise Guide has come along and many programmers with years of experience are often being asked to change their way of doing things with this new application. This paper shows how programmers can easily and successfully make the shift to programming the “EG” way without giving up their old comfortable coding habits. Don’t Take Away My Display Manager! So you’ve been programming with SAS for a long time and it’s always been using SAS ® Display Manager. “Why should I change?” you say. “Don’t fix what isn’t broken!” Well, now your company is bringing in SAS ® Enterprise Guide and wants everyone to make the switch. So just how painful will this change be? It doesn’t have to be very painful at all. A programmer who wishes to continue to write their own code can continue to program with EG almost the exact same way they currently do it. And EG has a number of features that programmers, as they become more comfortable, can take advantage of. In this paper we’ll take a look at how EG can be used to access, write, modify, and store SAS programs, just like SAS Display Manager. Also we’ll see a couple of new features of the EG editor window, Autocomplete and Format Code. Then we’ll go on to see other features of EG that can improve how we use our programs, such as writing our code using EG’s tasks, using Prompts and Conditions with our programs. We’ll close by reviewing some custom tasks that you can add to EG, such as a Macro Variable Viewer window and a System Command task. Connecting to SAS with Enterprise Guide SAS has been available since 1976, around 38 years. Enterprise Guide Version 1 was released in October of 1999, almost 15 years ago. Now we are at release 6.1 of SAS Enterprise Guide. It has matured very nicely and now has lots of great features to help the experienced SAS programmers as well as new programmers. So first, let’s talk about how Enterprise Guide and SAS interact. We’re talking a form of Client/Server here. EG is the client where you build your SAS code, and SAS is the server. When you select the Run button to execute a program or task in EG, EG will find the appropriate server and submit it to SAS. SAS then executes the code, generates the results (new datasets, Log, Report) and sends those reports back to EG where you can then view the results. Very much like how you do it with Display Manager. But with some differences. So where does EG reside and where is SAS? Well, EG is always installed on a Windows platform, usually on the user’s local PC, but it could be installed on a Windows server. SAS however, can be on the user’s local PC, but increasingly more commonly it is installed remotely on a different machine. The operating system for SAS can be Windows, or UNIX, or the mainframe. When EG is

Upload: doanduong

Post on 06-Feb-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Web view“Experienced” Dogs, New Tricks: SAS® Enterprise Guide for SAS® Display Manager Programmers. Randall Cates, Principal Technical Training Specialist

“Experienced” Dogs, New Tricks: SAS® Enterprise Guide for SAS® Display Manager Programmers

Randall Cates, Principal Technical Training Specialist SAS Institute Inc., St. Louis, MO

ABSTRACTSAS® has been around since 1976, and programmers learned how to work with SAS code using the old standard SAS® Display Manager. Now SAS® Enterprise Guide has come along and many programmers with years of experience are often being asked to change their way of doing things with this new application. This paper shows how programmers can easily and successfully make the shift to programming the “EG” way without giving up their old comfortable coding habits.

Don’t Take Away My Display Manager!So you’ve been programming with SAS for a long time and it’s always been using SAS® Display Manager. “Why should I change?” you say. “Don’t fix what isn’t broken!” Well, now your company is bringing in SAS® Enterprise Guide and wants everyone to make the switch. So just how painful will this change be?

It doesn’t have to be very painful at all. A programmer who wishes to continue to write their own code can continue to program with EG almost the exact same way they currently do it. And EG has a number of features that programmers, as they become more comfortable, can take advantage of. In this paper we’ll take a look at how EG can be used to access, write, modify, and store SAS programs, just like SAS Display Manager. Also we’ll see a couple of new features of the EG editor window, Autocomplete and Format Code.

Then we’ll go on to see other features of EG that can improve how we use our programs, such as writing our code using EG’s tasks, using Prompts and Conditions with our programs. We’ll close by reviewing some custom tasks that you can add to EG, such as a Macro Variable Viewer window and a System Command task.

Connecting to SAS with Enterprise GuideSAS has been available since 1976, around 38 years. Enterprise Guide Version 1 was released in October of 1999, almost 15 years ago. Now we are at release 6.1 of SAS Enterprise Guide. It has matured very nicely and now has lots of great features to help the experienced SAS programmers as well as new programmers.

So first, let’s talk about how Enterprise Guide and SAS interact. We’re talking a form of Client/Server here. EG is the client where you build your SAS code, and SAS is the server. When you select the Run button to execute a program or task in EG, EG will find the appropriate server and submit it to SAS. SAS then executes the code, generates the results (new datasets, Log, Report) and sends those reports back to EG where you can then view the results. Very much like how you do it with Display Manager. But with some differences. So where does EG reside and where is SAS?

Well, EG is always installed on a Windows platform, usually on the user’s local PC, but it could be installed on a Windows server. SAS however, can be on the user’s local PC, but increasingly more commonly it is installed remotely on a different machine. The operating system for SAS can be Windows, or UNIX, or the mainframe. When EG is installed, your SAS administrator puts in all of the appropriate information so that connecting to SAS is transparent wherever it is. And if your company/department has licensed the SAS Business Analytics suite of tools, EG is just one of the different apps available and can work seamlessly with all of the other parts.

What about libraries? You can still use the LIBNAME statement to create your librefs, and your EG/SAS administrator also has the ability to set up libraries for you. That’s especially true with the SAS Business Analytics suite.

The lower left-hand panel of EG contains the Server List window that will show you your connection to SAS, and also will show your available librefs. Please note, after submitting your LIBNAME statements, you may need to refresh the window to see them. Figure 1 shows the Server List window and the position of the Refresh button.

Page 2: Web view“Experienced” Dogs, New Tricks: SAS® Enterprise Guide for SAS® Display Manager Programmers. Randall Cates, Principal Technical Training Specialist

Figure 1: Server list window showing the Local SAS server and libraries

Very briefly that’s how you work with EG and SAS.

Programming in Enterprise GuideOne of the first questions that SAS programmers ask is: “Can I run my existing programs in EG?” And the answer is: “Yes, absolutely.” You can almost seamlessly switch over to using EG as if it were the Display Manager.

One concept that is new with Enterprise Guide is the idea of a project file. This is a file that you store on your computer that contains everything you do with EG and SAS. It can contain program nodes, task nodes links to data files, and notes. This is a great way of keeping similar work together. Figure 2 shows a typical EG session with a project open.

Figure 2: Enterprise Guide open with existing project

However, if all you want to do is to continue writing SAS programs and save them separately, then all you need to do is open them in EG and start typing. Save them out to the appropriate folders on your hard drive. No need to save a project file. Your existing programs will execute seamlessly in EG just the same as in DM.

Page 3: Web view“Experienced” Dogs, New Tricks: SAS® Enterprise Guide for SAS® Display Manager Programmers. Randall Cates, Principal Technical Training Specialist

What about your programs that you wrote for SAS on UNIX or the Mainframe? If your EG session has been set up to use SAS on a UNIX or mainframe platform then your existing programs can still be executed through EG on your PC. Keep in mind that EG sends the code to SAS on the UNIX platform, so the UNIX conventions still apply (e.g. case-sensitive).

There are a few nice features of EG that can make your typing a bit easier. For instance if you have some code that doesn’t conform to SAS conventions you can have EG format the code. Here’s an example:

data CurrentEmployees;merge orion.employee_payroll (where=(Employee_Term_Date is missing) in=InPayroll) orion.employee_organization;by Employee_ID;if InPayroll=1;run;proc gchart data=CurrentEmployees;hbar Department/sumvar=Salary type=mean patternid=midpoint; title "Average Salary by Department";run;

This code is just jumbled together and is very hard to read. If you bring this into EG in an Editor window, you can go to the Edit Menu and select Format Code (Ctrl-B). EG will rearrange the code using normal SAS formatting conventions. That same code now looks like this:

data CurrentEmployees;merge orion.employee_payroll(where=(Employee_Term_Date is missing) in=InPayroll)

orion.employee_organization;by Employee_ID;if InPayroll=1;

run;

proc gchart data=CurrentEmployees;hbar Department/sumvar=Salary type=mean patternid=midpoint;title "Average Salary by Department";

run;

EG can also help you with it’s AutoCompletion process. You start typing the first two characters of a word and EG will open a drop-down window with possible SAS keywords. You then use your mouse to move down the list to the correct word and select the spacebar to complete the word in the program. The autocomplete feature will then offer a list of valid possible keywords to follow it. Autocompletion works for SAS keywords, valid PROC options, librefs, dataset names, even variable names and others.

Can you still use your F3 and other shortcuts? Yes. You can find a list of shortcut keys in the Help-> SAS Enterprise Guide Help.

As always with anything new, there are some differences that you should be aware of with programming in EG. First, you can’t use system commands in EG anymore (e.g. X command, Systask). And EG won’t allow you to use the ABORT statement. Also there is no FSEDIT or FSVIEW window.

The SAS Enterprise Guide Help menu contains a list of available shortcut keys.

Using EG TasksSo what about those EG tasks that we’ve heard about? Well there are a lot of them. EG 6.1 contains approximately 90 tasks and you can find them under the Tasks menu. Additionally, if you open a table in EG, there is also a series of menu items to be found at the top of the table view window where you can choose from. There are many tasks available to the novice and advanced programmer.

These tasks provide point-and-click interfaces to build SAS code. Many procedures are represented here. From PROC SORT, PROC PRINT, PROC TABULATE, to our graphics and statistical procedures. This is a quick and easy way to generate SAS procedure code that minimizes many common typing errors and creates elegant and clear SAS code. Finally, when you are almost done with generating the report, and wish to tweak the code yourself, you can copy the code from the task, and continue modifying it in a program editor window.

Finally, some of the more complex tasks have associated Wizard tasks with most of the common options available to create a report more quickly without having to look through many panels and choices. Figure 3 shows a panel from the Pie Chart Wizard.

Page 4: Web view“Experienced” Dogs, New Tricks: SAS® Enterprise Guide for SAS® Display Manager Programmers. Randall Cates, Principal Technical Training Specialist

Figure 3: Pie Chart Wizard

The Query Builder task is the task you would want to choose if you needed to manipulate your data. For example you may need to join tables together, create new variables, filter the data using simple and complex filter expressions, maybe even summarize the data. This particular task generates SQL code, particularly useful when you are accessing relational databases. See Figure 4.

Figure 4: Query Builder Task

And you can still start with the Query Builder, copy the code generated, and modify it by editing the program yourself.

Prompts and Conditions Enterprise Guide has a couple of great things that give programmers become even more control of programs and tasks. Those are Prompts and Conditions.

Page 5: Web view“Experienced” Dogs, New Tricks: SAS® Enterprise Guide for SAS® Display Manager Programmers. Randall Cates, Principal Technical Training Specialist

PromptsExperienced SAS programmers are very familiar with Macro variables and Macro programs that allow them to feed different values to programs to produce more flexible reports. These still work in EG. Prompts in EG store information in macro variables so as to feed SAS with appropriate values at the right time. When the user selects the task or program to execute, a window pops up asking the user for some value or values to determine the result output. Figure 5 shows an example of a prompt window for a bar chart. In this case, when the user chooses a variable name, the bar chart is executed and the report shows the use of that variable in the bar breakdown as well as in the title. See Figure 6.

Figure 5: Prompt in Action

Figure 6: Pie Chart

As seen in Figure 7, the lower left-hand panel of EG contains the Prompt Manager window that contains the list of prompts available in the project. Each project can contain as many prompts as are necessary. To create a new prompt, select the Add button at the upper left of the window.

Page 6: Web view“Experienced” Dogs, New Tricks: SAS® Enterprise Guide for SAS® Display Manager Programmers. Randall Cates, Principal Technical Training Specialist

Figure 7: Prompt Manager Window

The Add New Prompt window (Figures 8 and 9) contains two tabs, a General tab where you give the prompt a name and type the instruction that you want the user to see, as well as a few general options about how the prompt will work. The second tab is the Prompt Type and Values tab, where you define more specific instructions about the prompt, for example, what type of prompt (numeric, character, date, ranges, variable names, etc.), and how will the user choose a prompt value (fill in the blank, drop-down list, etc.).

Figure 8: Edit Prompt Window, General tab

Page 7: Web view“Experienced” Dogs, New Tricks: SAS® Enterprise Guide for SAS® Display Manager Programmers. Randall Cates, Principal Technical Training Specialist

Figure 9: Edit Prompt window, Prompt Type and Values tab

Once the prompt has been built, then the prompt name can be added anywhere a variable name might be used; a Wizard window, Task window, even a program. When using the prompt in a program, preface it’s name with an ampersand (&) since the value from the prompt will be stored in a macro variable of the same name. One final point about prompts, if you add them to a task or wizard, they are automatically used. But if you use a prompt in a program you still need to go to the Properties window for the program node and specify which prompt you have referenced.

ConditionsIn EG the programmer has the ability to add conditions to process flow items. For example, perhaps you have a report that needs to be executed each weekday, and not on the weekends. Another situation might be you want to generate a report but only if you know that a particular variable is clean. And if it does contain invalid values, then you want to generate an error report instead. Figure 10 shows a process flow with 4 programs linked together. The first program generates results, which are then used by the second program. The third and fourth program are alternate reports that should be chosen to run based on some result from the prior two tasks. Note the small flags on those two program icons which indicate the presence of a condition linking them.

Figure 10: Process flow with programs containing a condition

Conditions can be added to any task or program in your process flow. A good practice is to build the different tasks first and make sure they work correctly before adding conditions to test. Once you know that the tasks will work, you can then then Right-mouse click on the first task in the process flow and select Add Condition from the menu. Figure 11 shows the Edit Condition window which has a test for a macro variable value. If it tests out to be true, then the task “es01do1” will execute. The condition has a further option of Else run to execute “es01e03”.

Page 8: Web view“Experienced” Dogs, New Tricks: SAS® Enterprise Guide for SAS® Display Manager Programmers. Randall Cates, Principal Technical Training Specialist

Figure 11: Edit Condition window

Once the condition is set up, the programmer can then execute the entire process flow and EG and SAS will work independently to ascertain the value of the condition and execute the appropriate programs/tasks.

Custom Tasks, Making EG even betterMy final section relates to custom tasks that you can add to EG to help you with your work. Here are a few of them; the SAS Catalog File Viewer, the Macro Variable Viewer task, and the System Options viewer.

These tasks are not standard EG tools but have been built as free add-ons to EG. One warning: SAS doesn’t support the use of these tasks. When you download custom tasks to your EG, you can find them under the Tools -> Add-In menu.

The SAS Macro variable viewer is an add-on window where you can keep an eye on your macros and macro values. Figure 12 shows the viewer window. It’s what is called a “modeless” display which means that you can keep it open and continue working in EG. It will show by default all existing macro variables, and their values, if any. If you access multiple SAS servers, you can switch between them to see the macro variable values in each. Also you can filter the results to look for specific macro variables. It even has a quick Macro Expression test window where you can try out a macro expression.

Page 9: Web view“Experienced” Dogs, New Tricks: SAS® Enterprise Guide for SAS® Display Manager Programmers. Randall Cates, Principal Technical Training Specialist

Figure 12: The Macro Variable Viewer Custom task

Another nice custom task is the System Options viewer task. This acts similarly to the Macro viewer task; modeless, select a server, and refresh. But this task will show the SAS system options and their values.

Figure 13: System Command task window

Last one I want to look at is one which addresses a common complaint about Enterprise Guide from SAS programmers. That is that it is difficult to run system commands such as the X command or SYSTASK command in Enterprise Guide. You can add the System Command task to a project or process flow and it allows you to execute a system command in the middle of executing a set of programs and/or tasks. Figure 14 shows an example of this. I’ve set up a system command to copy a dataset to the Orion library site, and now I can run a program accessing that dataset.

Page 10: Web view“Experienced” Dogs, New Tricks: SAS® Enterprise Guide for SAS® Display Manager Programmers. Randall Cates, Principal Technical Training Specialist

Figure 14: The System Command task

These and many more custom tasks are available by visiting the SASDummy website: (http://blogs.sas.com/content/sasdummy/). Search for Custom Tasks.

ConclusionSAS programmers may have a bit of adjustment in switching over to SAS Enterprise Guide from SAS Display Manager. But one way to do this is to simply start by using EG just the same way that they once worked in SAS DM. Write SAS Programs. And as they continue to utilize EG and start realizing the potential advantages that EG has over DM, I suspect that many will wonder why they hadn’t made the move years ago.

Resources

TrainingSAS Enterprise Guide for SAS Programmershttps://support.sas.com/edu/schedules.html?id=1294&ctry=US

Creating Reports and Grapsh with SAS Enterprise Guide https://support.sas.com/edu/schedules.html?id=1902&ctry=US

Video Training, Free SAS TuturialsFree tutorials to teach you the basics of using SAS Enterprise Guidehttp://support.sas.com/training/tutorial/#s1=5

BooksThe Little SAS Book for Enterprise Guide 4.2http://www.sas.com/store/books/categories/getting-started/the-little-sas-book-for-enterprise-guide-4-2/prodBK_61861_en.html Susan J. Slaughter and Lora D. Delwiche

Basic Statistics Using SAS Enterprise Guide: A Primer http://www.sas.com/store/books/categories/usage-and-reference/basic-statistics-using-sas-enterprise-guide-a-primer/prodBK_61625_en.htmlGeoff Der and Brian S. Everitt

Special: Custom Tasks for SAS Enterprise Guide Using Microsoft .NEThttp://www.sas.com/store/books/categories/usage-and-reference/custom-tasks-for-sas-enterprise-guide-using-microsoft-net/prodBK_61874_en.htmlChris Hemedinger

Page 11: Web view“Experienced” Dogs, New Tricks: SAS® Enterprise Guide for SAS® Display Manager Programmers. Randall Cates, Principal Technical Training Specialist

Web Links:The SAS Dummyhttp://blogs.sas.com/content/sasdummy/

SAS Talkshttp://support.sas.com/community/events/sastalks/index.html

The SAS Enterprise Guide community, an active discussion forumhttps://communities.sas.com/community/support-communities/sas_enterprise_guide

BI-Notes.com, a blog with contributors outside of SAShttp://bi-notes.com/

Platformadmin.com, a blog for SAS administrators addressing topic of concern for those supporting SAS usershttp://platformadmin.com/blogs/paul/

SAS Admin topics, a SAS blog for administratorshttp://blogs.sas.com/content/sgf/tag/sas-administrators/

Contact Information

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

Randall CatesPrincipal Technical Training Consultant – Education Division6719 Bradley Ave.St. Louis, MO 63139E-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.