Previous Page | Next Page

Using the SAS Windowing Environment

Working with SAS Programs


Editor Window

When you work with SAS programs, you typically use the SAS programming windows (the Editor, Log, and Output windows). Of these programming windows, the Editor is the window that you might use most often. It enables you to do the following:

The Editor Window with Line Numbers Turned On

[The Editor Window with Line Numbers Turned On]

Note:   The Editor window shown here includes line numbers. You might find line numbers helpful when creating or editing programs. To toggle line numbers on or off, issue the NUMBERS command.  [cautionend]


Command Line Commands and the Editor

There are a number of commands that you might find useful while working on programs in the Editor. You can execute these commands from the command line:

TOP

scrolls to the beginning of the Editor.

BOTTOM

scrolls to the last line of text.

BACKWARD

scrolls back toward the beginning of the text.

FORWARD

scrolls forward toward the end of the text.

LEFT

scrolls to the left of the window.

RIGHT

scrolls to the right of the window.

ZOOM

increases the size of the window. You can issue this command again to return the window to its previous size.

UNDO

cancels the effect of the most recently submitted text editing command. Continuing to execute the UNDO command undoes previous commands, starting with the most recent and moving backward.

SUBMIT

submits the block of statements in your current SAS windowing environment session.

RECALL

returns to the Editor window the most recently submitted block of statements in your current SAS windowing environment session. Continuing to execute the RECALL command recalls previous statements, starting with the most recent and moving backward.

CLEAR

clears a window as specified. You can clear the Editor, Log, or Output windows from another window by executing the CLEAR command with the appropriate option as shown in the following examples:

clear pgm
clear log
clear output
CAPS

converts everything that you type to uppercase.

FIND

searches for a specified string of characters. Enclose the string in quotation marks if it contains embedded blanks or special characters.

CHANGE

changes a specified string of characters to another. Follow the command keyword with the first string, a space, and then the second string. The rules for embedded blanks and special characters apply. For example, you might specify

change 'operating system' platform

This CHANGE command replaces the first occurrence of operating system with the word platform. Note that the first string must be enclosed in quotation marks because it contains an embedded blank.

Note:   Some of the more useful command line commands have been listed here. Almost all SAS commands are valid in the Editor window. For more information about other command line commands, see Working with SAS Windows.  [cautionend]


Line Commands and the Editor

The left-most portion of the Editor window includes a numbered field. This field is where you enter line commands. These commands are denoted by one or more letters, and can move, copy, delete, justify, or insert lines.

Some common line commands include

When you use some line commands, you also need to specify a location. For example, if you type an M in the numbered field for a line in the Editor, then you must specify where you want the line of text to be moved. You can use the A (after) and B (before) line commands to specify a location.

If you type an A in the numbered field for a line, then the line of text that you want to move will be placed after the line marked with an A after you press the ENTER or RETURN key. If you type a B in the numbered field for a line, then the line of text that you want to move will be placed before the line marked with a B after you press the ENTER or RETURN key.

The following examples show how to use line commands to move a line of text in the Editor window to a new location. To make the following lines alphabetical, place the first line after the last line. To do this, use the M and A line commands:

m 001 Lincoln f Wake Ligon  135
00002 Andrews f Wake Martin 140
00003 Black   m Wake Martin 149
a 004 Jones   m Wake Ligon  142

After pressing the ENTER or RETURN key, your Editor window lines appear as follows:

00001 Andrews f Wake Martin 140
00002 Black   m Wake Martin 149
00003 Jones   m Wake Ligon  142
00004 Lincoln f Wake Martin 135

There are many other line commands and combinations of line commands that you can use to edit the statements of a program in the Editor window. For more information, see Working with Text.


Output Window

You can browse and scroll procedure output from your current SAS session with the Output window. The results of submitting a program, if it contains a PROC step that produces output, are usually displayed in the Output window.

The Output Window Showing the Results of a Submitted Procedure

[The Output Window Showing the Results of a Submitted Procedure]

Most of the command line commands described earlier for the Editor window can be used in the Output window. The CLEAR command is particularly useful in the Output window because all output is appended to the previous output within a SAS session. If you want to avoid accumulating output, then execute the CLEAR command before you submit your next program. From any other window, you can clear the Output window by specifying

clear output


Log Window

The Log window enables you to:

The Log Window Showing Information about a SAS Session

[The Log Window Showing Information about a SAS Session]

The Log window shows the SAS statements that you have submitted as well as messages from SAS concerning your program. Under most operating environments, the Log window tells you:

You can use command line commands in the Log window, just as you can in the Editor and Output windows. For more information, see Editor Window.


Using Other Editors


NOTEPAD Window

Although the Editor was designed for writing SAS programs, you can also use the NOTEPAD window to create and edit SAS programs. The NOTEPAD is a text editor that you can use to create, edit, save, and submit SAS programs. You might find NOTEPAD useful as a separate place to work on code. To open NOTEPAD, issue the NOTEPAD or NOTES command.

The SAS NOTEPAD Window with Line Numbers Turned On

[The SAS NOTEPAD Window with Line Numbers Turned On]

Note:   The SAS NOTEPAD window shown here includes line numbers. You might find line numbers helpful when you create or edit programs. To toggle line numbers on or off in NOTEPAD, issue the NUMBERS command.  [cautionend]

If you open multiple NOTEPADS, then you can cut, copy, and paste text between NOTEPAD windows and the Editor window, multiple SAS sessions, and other applications.

Note:   To submit a program from NOTEPAD, you must either select Run [arrow] Submit or issue the NOTESUBMIT command.  [cautionend]

Note:   The program information that is presented in this documentation uses the Editor windows as the default editor.  [cautionend]


Creating and Submitting a Program

To create and submit a SAS program:

  1. Type the text of your program in the Editor.

  2. Type submit on the command line, and then press ENTER or RETURN.

    You can also use the function key, menu command, or toolbar item that is assigned to submit programs in your environment.

    Note:   If you are submitting a program from the SAS NOTEPAD window, then you must use the NOTESUBMIT command instead of the SUBMIT command.  [cautionend]


Storing a Program

To store a program:

  1. In the Editor window, create or edit a program.

  2. On the command line, issue the FILE command followed by a fileref or an actual filename. If you use an actual filename, then enclose it in quotation marks.

The FILE command does not clear the contents of the Editor window. You can store one copy of a program and then continue working in the Editor window.

If you try to store a program with a fileref or filename that already exists, then SAS displays a dialog box. The dialog box enables you to choose to

Often you will want to replace a file with an updated version. To suppress the dialog box, add the REPLACE option to the FILE command after the fileref or complete filename. To add the text in the Editor window to the end of an existing file, specify the APPEND option with the FILE command after the fileref or complete filename.

Note:   You can also store a program as a SAS object or as a file that is specific to your operating environment. After you have created or edited a program, select File [arrow] Save As Object or File [arrow] Save As, respectively.  [cautionend]


Debugging a Program

You or someone in your organization might be able to help debug a program with the information that appears in the Log window after a program is submitted. If you are having problems with your program, save the contents of the Log window to an external file, if you need to study it after your SAS session has ended.

To save the contents of the Log window to an external file:

  1. Open the Log window if it is not already open.

  2. From the command line, execute the FILE command followed by a fileref or an actual filename. If you use a filename, then enclose the name in quotation marks.

The FILE command stores a copy of the information in the Log window without removing what is currently displayed. If you specify the name of an existing fileref or file, then a dialog box appears and offers you three choices: overwriting the contents of the existing file with the new file, appending the new file to the existing file, or canceling the command.


Opening a Program

There is more than one way to open a SAS program. Two of the most popular methods are listed in this section.

To open a SAS program from the Editor window:

  1. Select:File [arrow] Open.

  2. Use the Open window to locate the appropriate SAS program file.

To open a SAS program with commands:

  1. Open the Editor window if it is not already open.

  2. On the command line, specify the INCLUDE command followed by an assigned fileref or an actual filename. Remember to enclose an actual filename in single or double quotation marks.

    By default, a program is appended to the end of any existing program statements.

Note:   If program statements already exist in the Editor, then you can determine where your program is appended by using the B (before) or A (after) line commands. For more information about line commands, see Line Commands.  [cautionend]

If you want to replace the text that is already in the Editor window with the program that you open, then specify the REPLACE option with the INCLUDE command after the fileref or filename.


Editing a Program

To edit a program:

  1. Open an existing program in the Editor window.

  2. Edit existing program statements or append new statements to the program.

    Use command line commands and line commands as needed.

  3. Store the program.


Assigning a Program to a File Shortcut

You can assign a program to a file shortcut to make it easier to find and work with the file in the future. For more information about file shortcuts, see Assigning a File Shortcut.

Previous Page | Next Page | Top of Page