Chapter 2: SAS Studio Tasks

Introduction

Using the Built-in Tasks

Taking a Tour of the Navigation Pane

Exploring the LIBRARIES Tab

Moving Columns

Sorting Columns

Filtering a Table (subsetting rows)

Conclusion

Introduction

Hopefully, you have installed your visualization software and the SAS University Edition (or you are running SAS Studio with a standard version of SAS). Now, it's time to get started. You start your virtual computer by double-clicking on the appropriate icon on your desktop (the installation process should have placed this icon there). If you don't see an icon for VirtualBox or one of the versions of VMware, you need to browse through your program list and create a shortcut on your desktop.

As an example, here is what you will see if you open VirtualBox:

Figure 1: Opening VirtualBox

image

Your screen may look a bit different. Double-click SAS University Edition.

A window will pop up that looks like this:

Figure 2: Opening SAS University Edition (VirtualBox)

image

The URL may be different from this. Once you enter it into your browser, you will want to bookmark it so that you don't have to type it every time you want to run the SAS University Edition. If you use a version of VMware, the URL will look something like an IP address such as

http://192.168.117.129

Regardless of which virtualization software you use, you will be directed to the SAS University Edition: Information Center screen. It looks like this:

Figure 3: Opening Screen of SAS University Edition: Information Center

image

If you see a message telling you that updates are available, you can click the Update icon or click the Start SAS Studio button and update at some other time. The Resources link is also very valuable—you can access help files, videos, books (even some of mine), and the always popular FAQs (frequently asked questions).

Using the Built-in Tasks

To open SAS Studio, click "Start SAS Studio."

Figure 4: Opening Screen for SAS Studio

image

As you can see in Figure 4, the rectangle on the left is called the navigation pane and the larger rectangular area on the right is called the work area. The navigation pane, as the name implies, allows you to select tasks, browse files and folders, import data from a variety of sources such as Excel workbooks, and do other useful tasks that you will see a bit later.

The work area consists of three sub-areas called Code, Log, and Results. You can switch to any one of these areas by clicking on the appropriate tab. This is what you see if you are in SAS Programmer mode. You see different tabs when you are in Visual Programmer mode. We will stick to SAS Programmer Mode for all the examples in this book.

The Code section is where you can write SAS programs (also the place where SAS Studio writes programs for you). The Log area displays information about data being read or written, syntax errors in your SAS code, and information on how much CPU time and total time were used to run your program. The Results area is where SAS Studio displays the tables, graphs, and statistics that either you programmed yourself or you had one or more of the built-in SAS Studio tasks produce for you.

Taking a Tour of the Navigation Pane

Figure 5 is an enlargement of the navigation pane.

Figure 5: Enlarged View of the Navigation Pane

image

When you click on any of the choices in the navigation pane, it expands and moves higher in the list. You can also expand or contract any of the sub-lists by clicking on the triangles to the left of the choices.

Exploring the LIBRARIES Tab

Let's start your exploration of SAS Studio by clicking the Libraries tab. Your Navigation pane will now look something like this:

Figure 6: SAS Libraries

image

Notice that the triangle to the left of the word Libraries is now pointing downward, telling you that you are looking at sub-lists. Under My Libraries, you see a list of libraries. Libraries are places where SAS puts programs and data sets (think of folders on your hard drive). This author has already created two libraries (BOOK and MYFMTS), so you will not see those libraries on your computer. However, SAS Studio comes with some libraries already installed. The WORK library is a temporary library—all data and programs placed there will not be automatically saved when you exit SAS Studio.

The SASHELP library contains over 200 data sets, covering a variety of topics such as car sales and health data. These data sets are quite useful because you can use them for examples or testing your code. Click the SASHELP library to see the list of built-in data sets (see Figure 7 below):

Figure 7: Expanding the SASHELP Libraries

image

Let's scroll down to the HEART data set to demonstrate some of the features of SAS Studio. You can either double-click the HEART library or highlight it or drag it to the work area. When you do this, SAS Studio displays the columns of the table and a listing of some of the top rows and columns of the actual table.

Note: Throughout this book and in the various SAS Studio tasks, the terms Columns and Variables, Rows and Observations, and data sets and tables are used interchangeably. Originally, SAS used the terms Variables, Observations, and data sets instead of the terminology that came along with many database programs (such as SQL) where the terms Columns, Rows, and tables were used instead.

Having opened the HEART data set, your screen will look as follows:

Figure 8: The HEART Data Set

image

The Columns (variables) in the data set are displayed on the left (Figure 9):

Figure 9: Columns in the HEART Data Set

image

You can click Select all to toggle between selecting all the variables or none. You will see two easy ways to select columns in just a moment.

The right side of the screen shows a portion of the actual table (Figure 10):

Figure 10: Columns and Rows from the HEART Data Set

image

You can use the horizontal and vertical scroll bars to examine additional columns and rows of this table (Figure 11):

Figure 11: Horizontal and Vertical Scroll Bars

image

As promised, you will now see how to select (or deselect) columns from a table. If you want to display just a few columns, it is best to click Select all to deselect all of the columns. Then, to select the columns that you want, using one or both of these methods:

1) Click the check box of any column to select it—it will be displayed in the table. If a column is already selected, you can deselect it if you uncheck it.

2) Click the check box of one column, hold down the Shift key and double-click the check box of another column. All columns from the first to the last will be selected.

In Figure 12 (below), columns for Sex, Height, Weight, Diastolic (diastolic blood pressure), and Systolic (systolic blood pressure) were selected.

Figure 12: Selecting Variables

image

To resize a column, move the cursor to the right side of a column on the top row of the table (where you see the column headings). When the cursor turns into two parallel lines, hold down the left-click on your mouse (or touch pad) and drag the column boundary right or left (see Figure 13 below).

Figure 13: Resizing Columns

image

Moving Columns

To move a column, place the cursor on a column name in the top row. It will change shape and become a hand. For example, if you want to move the column labeled Diastolic, place the cursor on the column heading for Diastolic (Figure 14):

Figure 14: Moving Columns (first step)

image

Hold down and left-click the mouse button, drag the column to the desired position, and release the button. For example, if you want Diastolic to be next to Systolic, drag the hand pointer to the column to the right of Systolic (and to the left of the Weight label). (See Figure 15 below):

Figure 15: Moving Columns (second step)

image

Release the left mouse button and the column is moved. (See Figure 16 below):

Figure 16: Moving Columns (final result)

image

Sorting Columns

There are two ways to sort a column. The first method is to place the cursor on the column heading (as if you were planning to move it) and left-click the mouse. A black triangle will appear, pointing up, to indicate that the column is sorted in ascending (low to high) order. (See Figure 17 below):

Figure 17: Sorting Columns (method 1)

image

If you repeat this process, a descending sort will be performed (Figure 18):

Figure 18: Descending Sort (method 1)

image

Each time you left-click on a column heading, the column is re-sorted in the opposite direction that it was before.

You can have more control over the appearance of a column, or even the whole table, if you right-click on a column heading. This causes the following menu to appear:

Figure 19: Sorting, Filtering, and Resizing

image

The top two entries provide a second way to sort, either ascending or descending. The third selection, Sort by Data Order, returns the table to its original order. You can Add a Filter to subset rows of the table. If you click the option Size grid columns to content, the column widths will all adjust so that they are the minimum size to hold the values in each column. Using this option is much easier than trying to resize each column manually. The last item in the list restores the column widths to the original size.

As an example of executing some of the right-click options, Figure 20 was produced by executing a descending sort on the column labeled Systolic and sizing grid columns to content.

Figure 20: Descending Sort and Sizing Grid Columns to Content

image

Filtering a Table (subsetting rows)

You can subset rows in a table by selecting the Filter option shown in Figure 19. Suppose you want to filter the table so that it will contain only rows where Height is greater than 70. First, right-click the column heading Height. Click Add Filter. This brings up a series of conditions (such as equal to, greater than, less than, and so on). Select the operation you want and then enter a value in the text box to the right. In this example, you want to select all rows where Height is greater than 70. You can click the box labeled Filter to complete the task or click the + sign to add other conditions. In this example, you only want the single filter to operate.

Figure 21: Filtering Rows

image

The filtered table is shown in Figure 22 below:

Figure 22: Filtered Table

image

If you add multiple filters, either all at once using the + sign to add more filters or right-click on another column and add another filter, the effects are additive. Each filter you create is displayed at the top of the table next to the filter icon (and label). To remove a filter, click the X to the right of any filter to remove it (see Figure 22, below):

Figure 23: Removing a Filter

image

If you create a filter based on a column of character data (see the "A" to the left of the variable name in the list of columns), the filter options show all possible values of the variables and allow you to select one or more values to create your filter.

As an example, suppose you want to see a table containing only female subjects. Right-click the column labeled Sex and click "Female." The table now contains only data for females (see Figure 24 below):

Figure 24: Filtering on a Character Value

image

Figure 25: Females Selected

image

For character columns that have multiple values, you can select several values by one of two methods:

1) Hold down the Control key and click each value you want to include.

2) Click a single value, hold down the Shift key, and click a second value. All values from the first to the second are selected.

You can combine these two method if desired.

Conclusion

In this chapter, you saw how to use built-in SAS Studio tasks. You learned how to select data files from the SASHELP library, move, sort, and resize columns, and how to filter rows of a table. The next step is to perform these operations on your own data. Chapter 3 shows you how to import data from Excel workbooks or raw data form text files and create SAS data sets.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.40.32