Starting SAS

Use SAS Interactively or in Batch Mode

When running SAS under Windows, you can start an interactive session to submit programs and view the resulting output, or you can execute batch SAS jobs, and view the output later.
By default, invoking SAS begins an interactive SAS session. If you have a SAS program that you want to submit as a batch job, specify the SYSIN system option with the name of the SAS program file when you invoke SAS.
When you start SAS in an interactive session for the first time, you are asked if you want to learn some basic tasks by taking the Getting Started Tutorial. To start the tutorial, click Start Tutorial. If you do not want to be prompted to take the tutorial, select Don't show this dialog box again. You can start the tutorial at any time by selecting Helpthen selectGetting Started with SAS Software.
The following examples show executing SAS batch jobs under Window 95, 98, NT, ME, and Windows 2000 operating systems.
  • If SAS is registered properly, open Explorer and right-click on the program to be executed. SAS should be registered properly when you install SAS the first time. If SAS is not registered properly, see the example on the next page. Select the Batch Submit option. This option executes the program as a batch job. The .LOG and .LST files are, by default, located in the same folder as the program.
    The .LOG file is the log for the program that has been executed.
    The .LST file is the output file for the program that has been executed. This file is created only if there is output for the program.
    You can also run .SAS files in batch when you double-click on the files within Explorer. The default action for .SAS files must be set to Batch Submit.
    To change the default action for .SAS files:
    1. Open Windows Explorer and Select Viewthen selectOptions.
    2. Now Select File Typesthen selectSAS System Program.
    3. Select Edit.
    4. Highlight the Batch Submit action and SelectSet Defaultthen selectOK.
    5. Double click a .SAS file to execute the SAS program in batch mode. The .LOG and .LST files will be created in the same folder as the .SAS file.
  • This example uses the SAS executable command with the -SYSIN option:
    1. Select Startthen selectRun.
    2. Type a command similar to the following: ”c:\Program Files\SAS Institute\SAS\V8\Sas.exe” -sysin c:\test.sas. Specify the location of the program. This example runs the TEST.SAS program that is located in root of the C drive. To eliminate the splash screen, use the –NOSPLASH option. Add the -ICON option to minimize the DOS window when the program is started. The resulting .LOG and LST files reside in the SAS root directory.
      The -SYSIN option specifies the SAS program file that will be run in batch. The path must be a valid Windows path.
  • This example uses a .BAT file. A .BAT file is executed by the operating system.
    1. Create a file in Notepad or a similar text editor.
    2. Type a command similar to the following: ”c:\Program Files\SAS Institute\SAS\V8\Sas.exe” -sysin c:\test.sas.
    3. To execute the .BAT file, select Startthen selectRun or double-click on the .BAT file.
      The resulting .LOG file and the .LST files reside in the folder of the .BAT file. To change the destination of the .LOG and .LST file, use the -LOG and the -PRINT options.
      Use the -PRINT option to change the destination folder for the output of the program. Use the -LOG option to change the destination folder for the log of the program that has been executed. "C:\Program Files\SAS Institute\SAS\V8\Sas.exe" -SYSIN c:\testprog.sas -NOSPLASH -ICON -PRINT c:\test.lst –LOG c:\test.log
      Note: Running a .BAT program opens a DOS window, which will not close until the job is finished.
    You can execute multiple programs within the .BAT file. The following example executes five programs concurrently:
    ”c:\Program Files\SAS Institute\SAS\V8\Sas.exe” —sysin c:\test1.sas
    ”c:\Program Files\SAS Institute\SAS\V8\Sas.exe” —sysin c:\test2.sas
    ”c:\Program Files\SAS Institute\SAS\V8\Sas.exe” —sysin c:\test3.sas
    ”c:\Program Files\SAS Institute\SAS\V8\Sas.exe” —sysin c:\test4.sas
    ”c:\Program Files\SAS Institute\SAS\V8\Sas.exe” —sysin c:\test5.sas
  • This example shows how to use the START command to run concurrent batch jobs for Windows 2000 and Windows XP. The START command requires a title. The title can be in double quotes but this example uses Job#.
    Start "Job1" ”c:\Program Files\SAS Institute\SAS\V8\Sas.exe” 
    —sysin c:\test1.sas
    Start "Job2" ”c:\Program Files\SAS Institute\SAS\V8\Sas.exe” 
    —sysin c:\test2.sas
    Start "Job3" ”c:\Program Files\SAS Institute\SAS\V8\Sas.exe” 
    —sysin c:\test3.sas
    Start "Job4" ”c:\Program Files\SAS Institute\SAS\V8\Sas.exe” 
    —sysin c:\test4.sas
    Start "Job5" ”c:\Program Files\SAS Institute\SAS\V8\Sas.exe” 
    —sysin c:\test5.sas
  • You can also create a batch (TEST.BAT) file that will execute five programs consecutively. The log (.LOG) and output files (.LST) are located in the directory where the .BAT file is located unless you use the –PRINT and –LOG options on the command line.
    This example applies to Windows 2000 and Windows XP. Type the following commands in the .BAT file:
    "C:\Program Files\SAS Institute\SAS\V8\Sas.exe" 
    —sysin c:\test1.sas
    "C:\Program Files\SAS Institute\SAS\V8\Sas.exe" 
    —sysin c:\test2.sas
    "C:\Program Files\SAS Institute\SAS\V8\Sas.exe" —sysin c:\test3.sas
    "C:\Program Files\SAS Institute\SAS\V8\Sas.exe" 
    —sysin c:\test4.sas
    "C:\Program Files\SAS Institute\SAS\V8\Sas.exe" 
    —sysin c:\test5.sas
  • You can use a scheduler to run SAS jobs at a specific time. When they are scheduled, the programs can be executed without operator assistance. The Scheduled Tasks program is located under My Computer for Windows NT 4 and is located in the Control Panel under Windows 2000 and Windows 98 and ME. Windows 95 does not have this scheduler.
    1. Double-click on the Scheduled Tasks icon to invoke the Scheduled Task Wizard.
    2. Select the Browse button and select the TEST.BAT file.
    3. Select how often this task should be executed. Select Next.
    4. Select the date and time that you want the program to be executed. Select Next.
    5. Enter the user name and password that applies to this program. Select Next. A confirmation message is displayed.
    6. Select Finish.

Starting from the Start Menu

To start SAS from the Windows Start Menu:
  1. Click Start.
  2. Select Programs.
  3. Select SAS.
  4. Select SAS 9.3 (Language) .

Starting from Custom Shortcuts or Program Items

During installation, the Setup program automatically creates a program item in the Start menu that you can use to start SAS. However, you can create multiple SAS items within a folder to represent several differently configured SAS sessions. Also, if you want SAS to start every time you start Windows, you can place a program item or shortcut in the Start up folder. For information about creating shortcuts, see your Windows documentation.
After you have created a shortcut to SAS, you can append system options to the SAS command. To append system options:
  1. Open the SAS Properties window and click the Shortcut tab.
  2. In the Target field, append the system options to the SAS command. Remember that double quotation marks are required around pathnames. For example,
    "c:\program files\SAS\SASFoundation\9.3\sas.exe" -config "c:\mydir\sasv9.cfg"

Starting from the Run Dialog Box or a Command Prompt

Specifying the SAS Configuration File

If you start SAS by using a command line (either from the Run dialog box or the Command Prompt window), you might want to specify the SAS configuration file location through the CONFIG system option. Even if you use the default configuration file SASV9.CFG, specify the file to ensure that SAS uses the configuration file that you want. For more information about how SAS searches for the configuration file, see How SAS Finds and Processes Configuration Files.
When the WORK and SASUSER system options are set, the Work and Sasuser data libraries reside in the specified paths regardless of the path from which you invoke SAS. For more information about the Sasuser data library, see Profile Catalog . For more information about the Work data library, see Work Data Library .

Using the Run Dialog Box

To start an interactive session by using the Run dialog box
  1. Select Startthen selectRun
  2. In the Open field, type the path and the exact name of the program file, including the extension and options.
  3. Click OK.
For example, if SAS is installed in the default folder c:\Program Files\SAS\SASFoundation\9.3, you type c:\program files\SAS\SASFoundation\9.3\sas.exe, and the options that you want to specify.
Note: For Vista and Windows 7, you must specify a fully qualified path to sas.exe in the Start Menu Search entry field.

Using the SAS Command from the Command Prompt

You can start either an interactive SAS session or a batch SAS job by typing the SAS command at the command prompt. For example, the following command starts an interactive session, specifies the page size and line size, and indicates the location of the SAS configuration file:
c:\program files\SAS\SASFoundation\9.3\sas.exe -ls 80 -ps 60
   -config c:\program files\SAS\SASFoundation\9.3\sasv9.cfg
This command starts a batch SAS job in a similar manner:
c:\program files\SAS\SASFoundation\9.3\sas.exe
   -sysin c:\mysas\programs\prog1.sas
   -config c:\program files\SAS\SASFoundation\9.3\sasv9.cfg
Note: These examples are displayed on multiple lines because of space limitations. When you enter a command from the command prompt, the command must be on one line.

Starting from a SAS File

There are two ways to start SAS from a SAS program file in Windows Explorer.
  • Double-click on a SAS program file
  • Right-click on a SAS program file and select the appropriate action.

Submitting a Batch SAS Job

How to Submit a Batch SAS Job

There are several ways to submit a batch SAS job:
  • Specify the SYSIN system option in the SAS command (issued from the command prompt or from the Run dialog box) to specify the SAS program to submit.
  • Right-click a file that has a .sas or .sasv7bpgm file extension. From the pop-up menu, select Batch Submit.
  • Use the Windows Explorer and drag your SAS program file icon (the file that contains the SAS code) to the SAS.EXE file icon or shortcut.

The Status Window

When you run SAS in batch mode, SAS displays a Status window for the SAS job that you submit. This window tells you the name of the SAS job that is running and where your log and procedure output files are written. This window remains open until the SAS job is complete.
If you do not want to see thestatus window while your batch SAS job is running, invoke SAS with the ICON system option so that the status window becomes an icon when your job is running. You can also minimize the status window by clicking the Icon button when the window appears. The icon shows the busy cursor (usually an hourglass) while the SAS job is running. The icon disappears when the job is complete.

Canceling a Batch Job

You can cancel a batch job by using either the keyboard or the mouse:
  • press CTRL+BREAK
  • click Cancel in the Status window.

Windowing Procedures in a Batch Job

You can run windowing procedures along with SAS/GRAPH, SAS/INSIGHT, and SAS/ACCESS software, in a batch SAS job. When SAS reaches a point in your program where interaction is required, it opens the main SAS window.

Starting the Program Editor When SAS Starts

The Enhanced Editor is the default editor that starts when you start SAS. If you prefer to use the Program Editor, use one of the following methods to start the Program Editor when SAS starts:
  • Start SAS with the NOENHANCEDEDITOR system option:
    sas.exe -noenhancededitor
  • Disable the Enhanced Editor in the Edit tab of the Preferences dialog box.

Determining the Current Folder When SAS Starts

By default, SAS determines the current folder. SAS uses the current folder as the location to read and write SAS files when you do not specify a different pathname.
SAS also searches the current folder, based on the following statements, for the AUTOEXEC.SAS file or INITSTMT files. In this case, the path that the SASINITIALFOLDER system option specifies is disregarded.
However, you can specify a pathname to use for the current folder by using the SASINITIALFOLDER system option when you start SAS. Alternatively, you can use the following rules to determine the current folder:
  1. If you use a program item or shortcut to start SAS and if a path is specified in the Windows Properties Shortcut tab (Start in field), SAS uses that path as the current folder.
  2. If you use a command to start SAS by using either the Run dialog box or a command line and if the command contains a path to the SAS.EXE file, the current folder is the path that you specify as part of the SAS command, regardless of where Windows actually finds the SAS.EXE file.
  3. If you use a command to start SAS and if you do not specify a path as part of the SAS command, then the current folder is specified by the path from which you issued the command.
If Windows cannot find the SAS.EXE file in the specified folder, the folder that is specified in the SAS command still becomes the current folder and Windows searches for the SAS.EXE file by using the Windows PATH environment variable.
For example, if you specify the following command, C:\MYSAS is the current folder, regardless of whether the SAS.EXE file is actually in that folder:
c:\mysas\sas.exe -config c:\mysas\sasv9.cfg
Note: Do not confuse the current folder with the Work data library. For more information about the Work data library, see Work Data Library .

Sample SAS Session

This section illustrates
  • invoking SAS from the Start menu
  • submitting a sample SAS program
  • examining the program output
  • ending the SAS session.
You can invoke SAS from the Start menu by, selecting Programsthen selectSASthen select9.3.
The following display shows the Enhanced Editor and Log windows with a sample SAS program that is ready to be submitted. This program creates a SAS data set called Oranges, which contains the results of a taste test on four varieties of oranges. The program sorts the data set by the total test score and prints the data set.
Submitting the Sample SAS Program
Sample program, oranges.sas, ready to be submitted
The following SAS code appears in the Enhanced Editor window:
ods rtf file="c:\em\oranges.rtf";
data oranges;
   input variety $ flavor texture looks;
   total=flavor+texture+looks;
   cards;
navel 9 8 6
temple 7 7 7
valencia 8 9 9
mandarin 5 7 8
;
proc sort data=oranges;
   by descending total;
run;
proc print data=oranges;
   title 'Taste Test Results for Oranges';
run;
ods rtf close;
After you submit the program, the output appears in the Results Viewer window as follows:
Looking at the Program Output
Results of submitting oranges.sas in the Results Viewer
The items in the SAS menu bar at the top of the main SAS window change, depending on which window is active within the SAS session. In addition, you can access window-specific pop-up menus, which offer the same menu choices. The pop-up menu in the following display was generated by right-clicking in an Enhanced Editor window.
Pop-up Menu in the Enhanced Editor Window
Pop-up menus in the editor window
When you are ready to end your SAS session, double-click the SAS control menu (the small icon in the upper left corner of the main SAS window) or click the X (in the upper right corner) and click OK when the dialog box verifies your request.
Note: If you have disabled the Confirm Exit of SAS option in the Preferences dialog box, your SAS session ends without asking if you are sure you want to end the session. For more information about how to customize your SAS session, see Setting Session Preferences .

What If SAS Does Not Start?

If SAS does not start, the SAS log can contain error messages that explain the error. Any error message that SAS issues before the SAS log is initialized is written to the MSG window, if it is available, or to the SAS console log, which is a Windows file. Under Windows Vista, Windows 7, Server 2008, and Server 2008 R2, the SAS console log is typically located in c:\Users\user-ID\AppData. In all other Windows operating environments, the SAS console log is typically located in c:\Documents and Settings\user-ID\Application Data. You can obtain the location and filename for the SAS console log from the application event log. To open the application event log, submit eventvwr from the Run dialog box and click Application.
If SAS does not start, if the screen appears and then disappears, or if SAS is very slow to open, you might have a problem with a missing printer, a damaged printer driver, or a failed network printer connection. Use the following steps to correct this problem:
  1. Verify that the printers are linking to valid network servers. If the printers are linking to invalid servers, then delete the printers by accessing Startthen selectSettingsthen selectControl Panelthen selectPrinters.
  2. Download a new printer driver from the printer's Web site and replace the current driver with the new driver.
  3. Rename profile2.SAS7bcat to profile2.old and rename profile.SAS7bcat to profile.old at c:\Documents and Settings\user-ID\My Documents\My SAS Files\9.3\.
  4. Start SAS.