15
1 Using the SAS® Explorer Window Nat Wooding, Hallsboro Systems Consulting, Midlothian, VA ABSTRACT The SAS® Explorer window is a feature of the SAS Display Manager used in installations on computers equipped with Microsoft Windows ® operating systems. It offers the user quick access both to the contents of SAS data sets and catalogs as well as to their metadata. Format options can be explored on the fly. If the SAS/ACCESS Software ® for Microsoft Excel®, etc., modules are licensed, the user may view external files from within SAS. The window is not a replacement for PROC CONTENTS but is a highly useful alternative. INTRODUCTION Hello. My name is Nat and for years I was a batch-oriented main frame bigot who ignored the capabilities of the SAS Explorer window. But now, I have seen the light. The intent of this presentation is to show the various features of this window and demonstrate how to use them during programming sessions. The target audience includes beginners as well as experienced users who may, like I, have ignored the functionality of this tool. It will cover the use of the window with SAS data sets and catalogs as well as Microsoft Excel ® spreadsheets and Access ® databases. The latter two instances assume, of course, that the user has licensed and installed SAS Access to Microsoft files. This paper is based on the Explorer Window’s features in SAS V. 9.1.3. The primary focus of this paper will be on working with SAS data sets but the reader should keep in mind that the Explorer Window will also work with SAS catalogs. THE SAS EXPLORER WINDOW vs. WINDOW’S EXPLORER (MY COMPUTER) The Windows Explorer is a useful tool for examining the folders and files in a directory but beyond providing the very basic information about a file such as the size and creation date, there are no provisions for seeing the equivalent of the information provided by Proc Contents. The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to see such information as variable names as well as to temporarily change some of the appearance attributes of the variables and make permanent on-the fly changes to a variable’s labels. Also, data sets can be edited. THE EXPLORER WINDOW TOOLBAR At the start of a SAS session, there are two vertical windows on the left side of the screen with the Explorer window displayed and the Results window hidden. When you right or left click anywhere in the Explorer window, the tool bar changes (Figure 1). Now, as shown in the screen shot, there are icons labeled “Toggle Details” and “Toggle Tree”. Selecting the “Details” icon stacks the icons that are currently displayed. When you drill down through the “Libraries” icon, varying amounts of information will be shown for subfolders and files. The “Toggle Tree” tool changes the view to one similar to that of Windows Explorer in that the Explorer window now has two panels with major folder level shown on the left and folder contents are displayed on the right. Foundations and Fundamentals NESUG 2010

Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

1

Using the SAS® Explorer Window Nat Wooding, Hallsboro Systems Consulting, Midlothian, VA

ABSTRACT The SAS® Explorer window is a feature of the SAS Display Manager used in installations on computers equipped with Microsoft Windows ® operating systems. It offers the user quick access both to the contents of SAS data sets and catalogs as well as to their metadata. Format options can be explored on the fly. If the SAS/ACCESS Software ® for Microsoft Excel®, etc., modules are licensed, the user may view external files from within SAS. The window is not a replacement for PROC CONTENTS but is a highly useful alternative.

INTRODUCTION Hello. My name is Nat and for years I was a batch-oriented main frame bigot who ignored the capabilities of the SAS Explorer window. But now, I have seen the light. The intent of this presentation is to show the various features of this window and demonstrate how to use them during programming sessions. The target audience includes beginners as well as experienced users who may, like I, have ignored the functionality of this tool. It will cover the use of the window with SAS data sets and catalogs as well as Microsoft Excel ® spreadsheets and Access ® databases. The latter two instances assume, of course, that the user has licensed and installed SAS Access to Microsoft files. This paper is based on the Explorer Window’s features in SAS V. 9.1.3. The primary focus of this paper will be on working with SAS data sets but the reader should keep in mind that the Explorer Window will also work with SAS catalogs.

THE SAS EXPLORER WINDOW vs. WINDOW’S EXPLORER (MY COMPUTER) The Windows Explorer is a useful tool for examining the folders and files in a directory but beyond providing the very basic information about a file such as the size and creation date, there are no provisions for seeing the equivalent of the information provided by Proc Contents. The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to see such information as variable names as well as to temporarily change some of the appearance attributes of the variables and make permanent on-the fly changes to a variable’s labels. Also, data sets can be edited.

THE EXPLORER WINDOW TOOLBAR At the start of a SAS session, there are two vertical windows on the left side of the screen with the Explorer window displayed and the Results window hidden. When you right or left click anywhere in the Explorer window, the tool bar changes (Figure 1). Now, as shown in the screen shot, there are icons labeled “Toggle Details” and “Toggle Tree”. Selecting the “Details” icon stacks the icons that are currently displayed. When you drill down through the “Libraries” icon, varying amounts of information will be shown for subfolders and files. The “Toggle Tree” tool changes the view to one similar to that of Windows Explorer in that the Explorer window now has two panels with major folder level shown on the left and folder contents are displayed on the right.

Foundations and FundamentalsNESUG 2010

Page 2: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

2

GETTING STARTED A word of caution: there are several levels though which we may drill in the Explorer Window and in each, a right or left click will give us a variety of different options. It is important to remember which level is being explored and whether a right or left click has been used. One convention that I will adopt will be to use “File” to refer to both SAS data sets as well as catalogs. At the beginning of a SAS session, the window displays four icons: “Libraries”, “File Shortcuts”, “Favorite Folders”, and “My Computer”. We will ignore the latter two icons (Figure 1) If we double left click Libraries, a new window will open which shows icons for the libraries that have been allocated to our session by SAS as well as any allocated by our AUTOEXEC.SAS (Figure 2). Once we issue LIBNAME statements of our own, we will see additional icons labeled with the LIBREF(s) used in our LIBNAME statement(s) (Figure 3).

Foundations and FundamentalsNESUG 2010

Page 3: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

3

EXPLORING A LIBREF At the LIBREF level, one may left click an icon and then will see the data sets and catalogs that are contained in the particular library (Figure 4). At the beginning of the session, the WORK library will be empty but the other libraries will contain SAS data sets and/or catalogs. If we have toggled the Details icon in the toolbar, we will see such information as file size, date modified, etc.; if we have not toggled the details, all we will see will be the list of files (Figure 5).

Foundations and FundamentalsNESUG 2010

Page 4: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

4

RIGHT CLICK A LIBREF ICON If you right click the icon, you will have several options presented: 1) OPEN which is functionally equivalent to left clicking the icon; 2) EXPLORE FROM HERE which opens a new window labeled “Contents of ...” where the ellipsis represents the name of the folder that has been opened. This presents the same information as was shown in 1); 3) FIND which opens a search window which will allow one to insert a prefix and find all sets/catalogs with that prefix in a given LIBREF. To search catalogs, you have to select “SEARCH CATALOGS”. Note that the results window gives statistics on the files and that the columns can be sorted by size, date, or name. To see all of the files in the LIBREF, specify “*” as the search term. 4) PROPERTIES which gives only the name of the LIBREF and the number of levels of subfolders. Personally, I see little use for this feature. There is one very important navigational issue that I need to emphasize here: when you click on an icon for a LIBREF and display the icons for the sets and catalogs, you may not see a tool-bar icon for going back up one level until you either left or right click somewhere in the explorer window.

EXPLORING A SAS DATA SET OR CATALOG Once we have left clicked the icon for a LIBREF, we can explore either the contents of the individual files or the metadata of the files. In order to avoid confusion as you read the following sections, keep in mind whether the discussion is aimed at the unopened or opened data set or catalog.

SAS DATA SETS Left Clicking the icon for a SAS data set opens it in a VIEWTABLE window and there is a new tool bar to deal with (Figure 6). The default setting is a table or spread sheet but an alternative setting shows a single observation in a manner somewhat reminiscent of PROC FSEDIT OR FSBROWSE in SAS/Full Screen Product (Figure 7). To see this, click on the Form View tool. I only recently started playing with the Form View feature and have never used it for actual work. However, it should be useful when proofing data since there would be no chance of reading from the wrong line in a table.

Foundations and FundamentalsNESUG 2010

Page 5: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

5

VIEWING A SAS DATA SET (THE VIEWTABLE WINDOW) We will focus on using the Detail View of a Viewtable. Once a set is opened in the Explorer window using a left click, there are several features available for working with it or for altering its appearance. These include: 1) printing the Viewtable Window 2) dragging columns to new positions ; 3) hiding columns 4) holding columns during scrolling 5) changing formats, fonts, and text and column color (individual cells may have their own color) –Beware: most of these are temporary changes!! However, new fonts will be retained if the viewtable is saved using Save AS. To print a Viewtable, use either the printer icon in the toolbar of the Print option found under File.

RIGHT CLICKING A COLUMN HEADER This opens the window shown in Figure 8. We will discuss all of the options in the figure except for “Column Description”. So far, I have not found that this option does anything.

Items 2 through 4 in the list above are done using options found by right clicking a selected column or group of columns. Selection is done using the Windows feature of left clicking a given column , releasing the mouse key ( the column is now high lighted), and then using either a Shift /Left Click to select a group of adjacent columns or a

Foundations and FundamentalsNESUG 2010

Page 6: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

6

series of CNTL/Left Clicks to select non-adjacent columns. To move this column or group of columns, execute a left click/hold/drag and move the cursor to the column to the left of where you want the column to appear. This drags the group to the desired location. Columns may be hidden from view by selecting one or more columns as described above and then doing a right click and selecting the “Hide” option. To unhide one or more columns, click on “Data” in the options list at the top of the screen, select the Hide/Unhide, option, and then using the arrow button move the desired variables from the “Hidden” group to the “Displayed” window and select “OK”. If you have a very wide viewtable and need to scroll to see all of the variables and you want to keep a left-side column in view during the scrolling, highlight that column, do a right click, and select “Hold”. As you scroll to the right, the “Held” column and those to its left will remain in view. The Viewtable Window has tools for modifying the displayed formats of the cells as well as there appearance. For me, the primary use of these features is to reformat a column which is not useful in its original format when I am trying to look for specific values. Dates presented as raw SAS date values are a good example. However, should one wish to go to the trouble, one could change colors of both columns as well as individual cells but as said before, these changes are not savable. I have not found a means of saving this information in a SAS data set but one can either print the file or save it as HTML. To change the appearance of the text, you have two approaches available. You may right click the header of a column (or a group of selected columns) and select either “colors”, “fonts”, or “column attributes” and the Column Attributes window will open or you can simply select the Column Attributes option (Figure 9). The distinction is that colors and fonts open those particular tabs in the window; column attributes opens a “general” tab where you will find the variable name, the label, and the format and informat. If you select the “Column Attributes” option, the aforementioned window will open with the information for the most recently clicked column appearing.

THE GENERAL TAB In the widow that opens, for the “general” tab, the format and informat are each displayed in a box in the window. Adjacent to each box is rectangular push button which, if depressed, will display many of the formats or informats for the variables type that available to the session. Note that as you scroll through the format/informat list, you may see formats or informats listed that you do not recognize and you can test them. This is one method of learning new formats and informats.

Foundations and FundamentalsNESUG 2010

Page 7: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

7

THE COLORS TAB

Here, we may independently change the foreground and background colors of both the column header and the data. As Figure 10 shows, there are four windows on the screen and each has an adjacent rectangular push button. When you press any of these buttons, you will be presented with a Color Editor window (Figure 11) which offers more options than I can cover in this paper.

Foundations and FundamentalsNESUG 2010

Page 8: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

8

RIGHT CLICKING A CELL IN A TABLE If one does a Right Click anywhere other than in a column header, the window shown in Figure 12 appears. Of the options, “Where” can be used to exclude from view rows that meet some criterion. To change the criterion or reshow the rows, select “Where Clear”. Clicking “Edit Mode” appears to do nothing other than close the window but if you do another right click, the window in Figure 13 appears offering several new options. The major option on this list is “Add Row”. Clicking it presents a one row version of the viewtable with all cells empty and you may now enter data in these cells. A further Right Click presents a new window (Figure 14). Selecting “Commit New Row” takes us back to our original view table but with the new row appended.

Foundations and FundamentalsNESUG 2010

Page 9: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

9

Having gone through all of this discussion about how to alter the appearance of a viewtable, I will again point out that the changes made above are ephemeral – I have found no way to save the new attributes and when we close and reopen a viewtable, the native form of the data set appears (note, however, the discussion of View Columns later on where permanent changes can be made). Although we cannot store the altered attributes of a SAS viewtable as attributes of the SAS data set, we can do

File/SAVE AS HTML and we will then store an HTML copy of the viewtable with all of the changes that we have made.

SO WHY GO TO THE TROUBLE OF ALTERING A VIEWTABLE?

Foundations and FundamentalsNESUG 2010

Page 10: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

10

Although we cannot make a permanent SAS copy of a modified viewtable, it does provide a quick means to rearrange and embellish a data set that we wish to print rather than going through a lot of ODS coding.

RIGHT CLICK A FILE ICON Now we will examine and work with the set’s metadata. Performing a Right Click on a file’s icon gives a list of options. These include Open View columns Print Query Export Copy Contents to Clipboard Save as HTML Copy Duplicate* Delete* Rename* Properties The three options above marked with an “*” will be active for user-written data sets but are “greyed out” for sets in SAS Institute-supplied libraries such as SASHELP. Of these options, “View Columns” is the most useful to me. When one first opens it, a Properties window for that data set opens as shown in Figure 15. The first tab gives the information on variables in the set (although “variable” appears as “column name”). It appears to open with thee names displayed in the order that they are stored in the set but left clicking the Column Name header sorts the rows alphabetically. This window is particularly useful when one has a wide data set and needs to verify that a particular variable is stored in it. One caveat for anyone whom may want to copy a variable name from the window for pasting into a program statement: you may highlight the name, right click the cell, click copy, and then do a paste operation. However, the entire contents of the window are pasted into target file. If anyone else would be interested in seeing a more useful cut and paste capability, watch the SASWare Ballot.

Foundations and FundamentalsNESUG 2010

Page 11: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

11

If you Right Click anywhere in the Properties window, you will see a small box containing the options “Modify” and “Copy” (Figure 16). If you click anywhere other than on the name of a variable, the box appears to be useless. However, if you Right Click the variable name and then select “Modify”, you will see a Column Properties screen (Figure 17). Here, you can make a permanent change to a variable’s label. While “Format” and “Informat” boxes are included in the window and you can select a different format, as soon as you close the window you receive the error message shown in Figure 18. Hence, the one useful feature available in this window is that of permanently modifying a variable’s label.

Foundations and FundamentalsNESUG 2010

Page 12: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

12

Foundations and FundamentalsNESUG 2010

Page 13: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

13

Foundations and FundamentalsNESUG 2010

Page 14: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

14

The other tabs available for Column Attributes provide the other metadata for a given data set and are essentially a live version of Proc Contents. The other options in the list above are self evident. For example, Export opens the SAS Export Wizard. The “Delete” option can be used with a single SAS data set or by using CNTL or SHIFT, one may select and delete a number of data sets. This is a simple and effective way to clean up a WORK directory after you gone through a variety of tasks and generated a number of WORK datasets.

SAS CATALOGS A Left Click on a Catalog icon will drill down one level and display icons for whatever SAS objects are stored in the catalog. For example, a format catalog will show the formats stored therein. A graphics catalog created with a GOUT option will show the graphs that have been stored in the catalog.

GOING BEYOND SAS FILES: USING THE EXPLORER WINDOW WITH EXTERNAL FILES So far, we have dealt with native SAS data sets and catalogs but if we have a license for SAS/Access Software for one or more external file types, then we can issue LIBNAME statements to references these files and the Explorer Window will treat them as if they were SAS files. My experience here has been with Microsoft products such as Excel and Access so I do not know how well the Explorer window works with other data bases. If you issue a Libname statement such as Libname DataIn ‘C:\myfiles\my workbook.xls’;

an icon for the new Libname will appear in the Explorer window along with SASHELP, SASUSER and WORK. However, such an icon will have a blue and green disk at the lower right-hand corner of the “file drawer”. Now, the user will have access to all the features that were available when working with SAS data sets. The various sheets and named ranges (sheet names with an appended “$”) will appear if the icon is left clicked. One feature that I have found useful is the ability to investigate the names of variables in Access tables when I had no other information on the tables.

EXPEDITING PROGRAMMING WITH THE HELP OF THE EXPLORER WINDOW Here, we will examine some uses that I have found for some of the windows features. While all of the information may be found via Proc Contents, the Explorer Window does offer a couple advantages. Questions that it has answered include: Am I seeing a variable name or a label? Why does SAS not recognize a variable name when I specify it? What is the type of my variable? Does a string contain non-printing characters? How would a variable look with a different format? How can I copy the names of all of the variables into my program? What are the names of the SAS data sets in a folder? Does a variable exist in a data set. When I encounter a data set that is new to me, especially one that I have read directly from an Excel workbook using the Excel engine or a file from a non-SAS data base, I often find that the column names presented in the Viewtable are not actual names. If the Excel column headers have embedded blanks or begin with something other than a character, SAS converts them into valid SAS names and puts the original header string into a label. Hence, what I see is not necessarily what is actually in the set. A check of a column’s attributes or opening View Columns will quickly allow me to recognize where I am being misled. Moreover, if I have opened the Column Attributes window, I can copy the actual variable name into my new SAS statements (note that this requires that the variable name be highlighted and then a Cntl A and a Cntl V to do the select copy operation. Highlighting followed by a right click will not offer a Copy option). The is particularly helpful if there is more than one blank embedded in a column header and, hence, more than one underscore between parts of the variable name. I, for one, get tired of trying to guess whether “A__B” has more than one underscore and how many are actually there. When working with a

Foundations and FundamentalsNESUG 2010

Page 15: Using the SAS Explorer Window - Lex Jansen · 2014-01-06 · The SAS Explorer window, however, is not as robust in terms of searching directories but provides both the ability to

15

number of new variables, especially if they are long, it can be useful to do a copy/paste from “View Columns” even though the result is messy and needs a lot of cleanup. Sometimes, character data from an external source will not “work” in IF statements when the variable is being tested against some string which to all appearances matches the string. The culprit can often be non-printing hexadecimal characters that appear as blanks. Opening the table as a viewtable and setting the format to $Hex may help you find the non-printing characters.

CONCLUSION

The SAS Explorer Window offers the Windows user the ability to examine both SAS data set content as well as the set’s metadata. This ability allows the programmer to quickly find pertinent information about unknown sets and to do ad hoc prints of these sets.

ACKNOWLEDGEMENTS

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.

CONTACT INFORMATION

If you should have questions or comments about this paper, you may reach me at:

Nat Wooding Hallsboro Systems Consulting 1000 Hallsboro Rd. Midlothian, Va 23112 [email protected]

Foundations and FundamentalsNESUG 2010