Report Writing |
A listing report displays data from a table. Using the Listing Report task, you can display all the data from a table, or a portion of the data, based on criteria that you specify. By following the instructions in this section, you can produce a report that shows the information for ranch-style homes from the HOUSES table. A listing report displays one line for each observation in the table.
Information on Ranch Style Houses Report
A table is a collection of information arranged in columns and rows. A column is a set of data values that represents a particular type of data; for example, the price of all the houses. A row is a set of data values for the same item; for example, all the information about one house, such as price, style, square footage, and so on. Refer to Setting Up SAS Files for more information about tables, rows, and columns.
Setting Up the Report |
To create a listing report, you first set up the report by following this selection path: Tasks Report Writing ListingThe List a Table window appears.
List a Table Window
If the active table is SASUSER.HOUSES, then continue to the next step. Otherwise, select , and then select the SASUSER.HOUSES table. For more information on selecting tables, see Selecting a Table.
If there is an active Subset Data selection (indicated with BY, WHERE, or ROWS next to ), then clear the selection. For more information, see Clearing a Subset Data Selection.
If other report selections exist (for example, is not -ALL-), then selectFile Newto clear these selections.
To produce a report that lists all the data in the HOUSES table, selectRun SubmitThe Listing Report appears in the Output window.
Listing of HOUSES Table
The listing report is a quick way to get a list of all the data in your table. Note the different styles of the houses. For the sample report shown in Information on Ranch Style Houses Report, only the RANCH style houses are selected.
If the report is wider or longer than the window, use the scroll bars or the FORWARD, BACKWARD, LEFT, and RIGHT function keys to look at the rest of the report. Refer to Using Function Keys for further information on function keys.
After you have finished looking at the report, return to the List a Table window by using one of the following methods, depending on your operating environment:
Note: Under some operating environments, if you are using the Output window and the report is longer than one display, the last display of the report is shown after you select Close once. In this case, select File and then Close again. The task window reappears.
Subsetting the Data |
To produce the report shown in Information on Ranch Style Houses Report, you need to subset and customize the report. Subset the data as follows:
Select in the List a Table window. The Subset Data window appears.
Subset Data Window
You subset the data if you want to produce a report that uses only some of the data in the table. For example, to produce the sample report shown in Information on Ranch Style Houses Report, you need to subset the data so that only data for ranch-style houses are used.
Select . The Build a WHERE Clause to Subset the Current Data window appears.
Build a WHERE Clause to Subset the Current Data Window
This window enables you to create a WHERE clause that specifies criteria for selecting rows. The rows that match the criteria in the WHERE clause are used in the report. For this example, you build a WHERE clause that selects only the houses for which the STYLE is RANCH.
You subset the data by using one of the following methods:
You can type the WHERE clause directly by selecting and typing STYLE='RANCH' under Edit the current WHERE clause.
You can build the WHERE clause by making selections from this window. The items that are available for selection are highlighted while you build the WHERE clause. For example, when the Build a WHERE Clause window appears, only the Column, Constant, Function, NOT, and Opening parenthesis items are highlighted because these are the only items that can begin a WHERE clause.
To build the WHERE clause using the items in the window, select Column from the Build a WHERE Clause window, and then select the STYLE column. For more information, see Selecting a Column.
Select Comparison operator from the Build a WHERE Clause window. A window with a list of valid comparison operators appears.
Select Data Window (Comparison Operators)
Select the equal operator from the Select Data window. The Build a WHERE Clause window reappears.
There are two ways to specify a constant value. Use one of the following methods:
Select Look up constants. SAS/ASSIST software searches the column and presents a list of unique values in the Select Data window.
Select Data Window (Look Up Constants)
Select RANCH and then select .Note: Using Look up constants prevents you from making typing errors. However, it is more useful when the number of possible values is small than when the number of possible values is large.
Select Constant from the Build a WHERE Clause window. The Enter a Character Constant window appears.
Enter a Character Constant Window
To select the ranch-style houses, type RANCH in the Value field. Make sure RANCH is in uppercase because all of the style values are in uppercase in this sample data.Any time you use a character string for a constant value in a WHERE or BY clause, you need to make sure you use the exact case of the character string in the table. If the word ranch had been in lowercase in the HOUSES table, you would type ranch .
Select . The Build a WHERE Clause window reappears. The WHERE clause that you built is shown under the WHERE clause being built item as shown in the following display.
Completed WHERE Clause
To make changes to the WHERE clause, select . You can then make changes to the column, comparison operator, and constant.
Note that in certain operating environments, there is an additional option to Verify where clause against data. If you select this option, then SAS checks to see if there are any rows that meet the conditions of your WHERE clause. If your table is very large, then this verification can take a long time.
Select and then to return to the List a Table window. Notice that the value in the Subset data field is WHERE. This value indicates that a WHERE clause is being used to subset your data.
Adding Titles |
You can customize the report by adding titles and footnotes, changing the page dimensions, and selecting headings. Follow these directions to add a title to your report:
Follow this selection path: Edit TitlesThe Titles window appears.
Titles Window
Select from the Titles window. The Title 1 window appears.
Title 1 Window
In the Title 1 field, type the title exactly as you want it to appear on the report. For this report, type the title Information on Ranch Style Houses . Select twice to return to the List a Table window.
Note: Because the same set of titles and footnotes is used for all SAS/ASSIST tasks, the titles and footnotes that you specified most recently in your SAS/ASSIST session are used unless you change or reset them. If a title already exists when you open the Titles window, then type the new title over the old title.
Running the Report |
After you have finished setting up the report, you can run the report.
Follow this selection path: Run SubmitThe report appears in the Output window.
Information on Ranch Style Houses Report
This report shows all the data for the ranch-style houses in the HOUSES table.
If the report is wider or longer than the window, use the scroll bars or the FORWARD, BACKWARD, LEFT, and RIGHT function keys to look at the report.
Printing the Report |
If you do not want to print the report, go to the next section. To print the report, follow these instructions.
Note: To ensure that row and column separators and boxed tabular reports will be printed legibly when using the standard forms characters, you must use these resources:
either the SAS Monospace or the SAS Monospace Bold font
a printer that supports TrueType fonts
Follow this selection path from the Output window: File PrintDepending on your operating environment, the output may be sent directly to your default printer, or you may see the Print window, where you can select printing options.
Print Window
Make sure the name of your default printer (or some other printer of your choosing) appears in the Default Printer field in the Print window. If it does not, then select and choose your printer from the list that appears. If you do not know which printer to choose, then contact the SAS Support Consultant at your site.
To print the current report, select in the Print window. The report is sent to your printer, and a message appears in the Output window that indicates how many lines were printed.
Exiting This Task |
When you have finished viewing or printing your report, return to the List a Table window by using one of the following methods, depending on your operating environment:
To return to the WorkPlace menu or move on to another task, follow the directions in Exiting a Task.
Copyright © 2012 by SAS Institute Inc., Cary, NC, USA. All rights reserved.