<<

NESUG 16 Posters

PS001 Creating Effective Graphical User Interfaces Using Version 8 SAS/AF® Anders Longthorne, National Highway Traffic Safety Administration, Washington, DC

ABSTRACT Improving access to an organization’s database can often result in large gains in productivity and therefore lead to improved response time to customers. This paper will show how this goal can be achieved using applications developed with SAS/AF software. Applications implemented using SAS/AF can be used by all workers within an organization, including those who do not have SAS® programming experience.

INTRODUCTION SAS/AF software provides a set of tools that allows for the development of powerful interactive and intuitive applications. The ability to produce applications of this kind can quickly help an organization to improve its productivity and therefore its response time to customers. A developer must have SAS/AF software licensed on his computer in order to start developing the type of applications that will be discussed in this paper. To run SAS/AF applications only requires a licensed copy of Base SAS. There have been many books and papers written on the subject of SAS/AF and therefore this paper will not concentrate on the technical details of SAS/AF. Instead this paper will give details regarding the steps needed to create a basic application. By learning how to create and manipulate a basic application, the door to using SAS/AF will be opened; and with further reading and practice a new user should be able to develop sophisticated solutions to an organization’s needs. This paper assumes that the reader has a good knowledge of Base SAS, the SAS Macro Language, the SAS Output Delivery System (ODS), and a basic understanding of object-oriented programming.

SAS/AF OVERVIEW SAS/AF software is a type of software that is generally known as object-oriented. Visual Basic, C++ and Java are other types of object-oriented software. Creating applications using object-oriented software is known as object-oriented programming (OOP). The key concept behind OOP programming is that a program is viewed as a collection of independent objects, where the objects have two characteristics: state (data) and behavior (operations that can be performed on the data). SAS/AF objects store their state within their Attributes. Attributes are variables that can be of the following types: Numeric, Character, List, Array and Object. Methods are functions that are used to change an object’s state. For a more detailed discussion, please refer to the SAS documentation referenced at the end of this paper.

CATALOGS SAS/AF applications are built around a SAS catalog. SAS catalogs are storage locations that are only usable by the SAS system. Catalog entries are stored within a SAS catalog. While there are many types of Catalog entries, this paper is going to concentrate on only two types: Frame entries and their related Screen Component Language (SCL) entries. Applications can be easily developed using just one catalog, however it is also possible to use multiple catalogs.

FRAME ENTRY Frame entries are windows within which instances of visual classes (controls or components) are placed. This is where the Graphical (GUI) for an application is developed. The GUI is usually the only part of an application that an end user will interact with and therefore proper design of a GUI is essential.

- 1 - NESUG 16 Posters

SCL ENTRY SCL entries can either be stand-alone programs or they can be linked to a Frame entry. When linked to a Frame, SCL entries can be used to provide functionality to the visual components of the Frame.

HOW TO DEVELOP A SAS/AF APPLICATION There are two ways to develop SAS/AF applications: using interactive development windows or using the Build Procedure. This paper will concentrate on using the interactive windows environment.

CREATE A CATALOG 1. First create a new SAS library. 2. Enter the new library via the SAS Explorer . 3. Select FILE -> NEW -> CATALOG 4. Name the new catalog and then click ok.

CREATE A FRAME ENTRY AND ITS ASSOCIATED SCL ENTRY 1. Enter the new catalog via the SAS Explorer window. 2. Select FILE -> NEW -> FRAME 3. A new window will open on the right side of the screen and a third pane, called Components, will be added along side the SAS Explorer and SAS Results window. The new window is the Frame entry. 4. Select FILE -> SAVE AS. Enter a name for the new Frame and click save. 5. Select VIEW -> FRAME SCL. This will open the associated SCL entry for the new Frame. The SCL entry will have the same name as the new Frame but it will be of the SCL entry type.

VISUAL COMPONENTS OVERVIEW The following table contains descriptions of some of the more generally useful visual components that are provided with SAS/AF. The visual components described in the table should provide enough functionality to allow a developer to produce effective applications.

Visual Class Name Appearance Description

Provides a switch for On/Off, True/False or Yes/No Check Box Control functionality.

Provides a drop down list of items from which an end Control user may select only one.

Provides a list of items from which an end user may Control scroll through and select one or more.

Provides a push that can be used to run a process Push Button Control or provide switch functionality that is similar to the Check Box Control. Provides mutually exclusive selection options, so that only one selection can be made at any time. Radio Box Control This Class is similar to the Combo Box Control except that all choices are visible. Text Entry Control Provides the end user an option to enter text.

Provides a text that is not editable by the end user. Text Label Entry These labels can be used to create page titles or to

provide help and guidance to the end user.

- 2 - NESUG 16 Posters

DEVELOP A SIMPLE APPLICATION USING A RADIO BOX VISUAL COMPONENT 1. Have the Frame and Components Window open.

2. Click on the Radio Box Control in the components window. Be sure to select from the Components list and not from the Version 6 objects list.

3. A Radio Box Control should appear in the Frame.

4. Click on the Frame and then Select VIEW -> PROPERTIES WINDOW. The Properties dialog window should open. On the left side of the properties window will be an expandable for all of the objects currently on the Frame. Expand RadioBox1 to view all of the possible Attributes, Methods and Events for the Radio Box Control Object. RadioBox1 is the default name for the object. This name can be easily changed by setting the object’s name attribute. There are many other attributes divided into categories such as Appearance, Behavior, and Data etc. All the visual components described in the above table have very similar attribute lists associated with them. All of these attributes can be either interactively manipulated, using the mouse or keyboard via the properties window, or they can be manipulated from within an SCL program. To discuss and understand the full power of all of these attributes is beyond the scope of this paper.

5. In the properties window select ATTRIBUTES -> DATA. Open the list located in the VALUES column of the ITEMS ATTRIBUTE row. This is where a developer may enter data to be used as selections by an end user. Something similar to the following should be visible:

- 3 - NESUG 16 Posters

6. Select Remove All. Use ADD to populate the list with data. This list now contains all possible selections to be displayed. Click OK and then close the properties window.

- 4 - NESUG 16 Posters

7. Something similar to the following should be visible:

8. In a short time we have developed a very simple (GUI). To add functionality to this GUI we will now open the associated SCL entry. Click on the Frame. Select VIEW -> FRAME SCL. Something similar to the following should be visible:

- 5 - NESUG 16 Posters

9. The SCL entry is where SCL code can be written to add functionality to the GUI. SCL is a fully developed and powerful programming language. A full discussion of SCL is beyond the scope of this paper. One very important feature of SCL programs is that they allow for the submission of SAS DATA STEP and SAS PROCEDURE statements to the SAS SYSTEM. This allows SAS/AF to be put to work without a programmer having to be an SCL expert first, although in the long run learning SCL will allow for even more powerful applications. SCL programs can be divided into what are known as Labeled Sections. These labeled sections allow for the development of modular code and for selective processing. The four main labeled sections are described below:

The INIT section is executed when the associated application window (Frame) is opened. This can be used to set an application’s initial conditions.

The MAIN section is executed each time a field (control or component) within an application window (Frame) is modified.

The RADIOBOX1 section is executed each time the RADIOBOX1 object is modified (when a selection is made). This section always executes before the MAIN section. Every visual component added to the Frame can have its own Labeled Section.

The TERM section is executed when an application window (Frame) is closed. This can be used to close files, tables, clean up old variables etc.

10. Remove all label sections except RADIOBOX1. Within a labeled section it is possible to place what are called submit blocks. Within these submit blocks can be placed SAS DATA STEP and SAS PROC statements. These statements are then submitted to the SAS SYSTEM for execution. For the following example, assume that the available selections on the RADIOBOX1 object are SAS databsets that an end user wishes to run PROC CONTENTS on.

- 6 - NESUG 16 Posters

SAS/AF Version 8 uses what is known as Dot Notation for returning (and setting) the value of an object’s attribute. The standard syntax for returning an attributes value is: CurrentValue = ObjectName.AttributeName. If the variable, CurrentValue is not defined then it will be automatically created.

Between SUBMIT CONTINUE; and ENDSUBMIT; can be placed SAS When finished with developing an DATA step and PROC statements. application select BUILD -> COMPILE. CONTINUE causes these statements This will compile an application and will to execute immediately. There are inform a developer of any problems via the options other than CONTINUE. Log window. Please see the SAS documentation referenced at the end of this paper.

The value of an SCL variable can be passed into submit blocks by placing a single ampersand (&) in front of the variable name. If there are also using Macro variables within an SCL program and there is a name conflict, then use two ampersands (&&) in front of the variable name in order to force the value of the Macro variable to be used instead.

11. Close the Frame after compiling with no errors. Right mouse click on the Frame in the Explorer window and select RUN. The application should open on the right of the screen. Test the functionality of the application and check the Log file for errors. Something similar to the following should be visible:

- 7 - NESUG 16 Posters

Run your application

Application should open on the right.

- 8 - NESUG 16 Posters

CONCLUSION The goal with this paper was not only to show the power of SAS/AF but to also show that getting started with SAS/AF need not involve weeks of study. Its intuitive point-and-click development environment is very user friendly and this allows for beginning SAS/AF programmers to see end results quickly. Once started, a developer, with practice and patience, should see satisfying improvements in the level of sophistication of his or her applications.

REFERENCES SAS Institute Inc., SAS Component Language: Reference, Version 8, Cary, NC: SAS Institute Inc., 1999 SAS Institute Inc., SAS/AF Software: Class Dictionary, Version 8, Cary, NC: SAS Institute Inc., 1999 SAS Institute Inc., SAS/AF Software Procedure Guide, Version 8, Cary, NC: SAS Institute Inc., 1999 Developing SAS/AF Applications Made Easy, Bernd E. Imken, SUGI28 Getting Started with SAS/AF Software, Steven A. Wilson, SUGI27 SAS/AF: It’s Not What It Used to Be!, Soora Wi, SUGI27

CONTACT INFORMATION Anders Longthorne US DOT, NHTSA, NPO-121, Room 2316 400 7th St., SW Washington, DC 20590 Tel: (202) 366-5356 Fax: (202) 366-7078 Email: [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 registered trademarks or trademarks of their respective companies.

- 9 -