Table of Contents


1.0 SAS on Athena


To put it simply, SAS is a powerful statistics package. In reality, though, SAS is far from simple. In fact, SAS is not really a single program, but rather a system that allows you to take data in any form and access, manage, analyze, and present it according to your needs and level of expertise. Using SAS, you can produce graphs, reports, and analyses of your data sets.

1.1 The SAS System

SAS is comprised of many modules. The base module provides basic data management facilities and tools to perform simple analysis, data transformation, and output. The base module interacts transparently with all the other modules licensed by and installed on Athena to provide extensive data processing capabilities. The interaction between modules is virtually seamless, so you often may not realize that you are using different modules. However, it is much easier to look up documentation if you do know, as both the online and printed documentation is arranged by module.

SAS is available on Athena Sun workstations (version 6.11 and 6.09). If there is sufficient interest, we can also install version 6.10 for the SGI platform. Please send mail to swmaint@mit.edu if you would like to have SAS installed for the SGI.

Formerly, SAS was a non-graphical command-line-based system -- you would submit programming commands and SAS would return its results in plain-text files at a simple terminal screen (i.e., an 80x24 window). If you made a mistake in entering the program, you would have to re-run the whole sequence. In this sense, SAS was basically a batch system. Because running SAS in a non-interactive mode requires the least SAS expertise, many people still prefer it.

Besides a batch mode and a text-only interactive mode, SAS has more recently taken strides into the era of windows. In addition to still supporting a command-line interface, on many computer systems SAS now also provides a flexible window-oriented user interface to accommodate both the novice and expert user. SAS on Athena offers a large set of menus that can help you interactively create, edit, and analyze data sets.

Whichever mode you choose, the modern SAS retains the proven statistical techniques for which SAS is universally recognized. Regardless of its interface, SAS is still the standard by which all statistical software is measured, in terms of the validity of its statistical results.

1.2 About This Document

Because the SAS system is so extensive, this document could not possibly cover all of its capabilities. Instead, it concentrates on the specifics of interfacing with the SAS system on Athena. Topics covered here include:

1.3 Other Available Documents

The SAS software comes with a tremendous amount of documentation. The Athena Consultants' Office (11-115) has about a third of the complete set (these documents take up about 3.5 feet of shelf space, which should give you some sense of how big the complete set is!) Feel free to browse these volumes in the Consultants' Office if you need to refer to them.

Several of the SAS reference publications are available on reserve in Hayden and Barker libraries, or for temporary loan (items must be returned the same day) from the Consultant's Office. These documents include:

For more information about SAS data sets, SAS procedures, the SAS display manager, or for help writing SAS programs, refer to the documentation that supports Version 6 SAS Software;

1.4 Other Sources of Help

The SAS institute has extensive information online at the URL

http://www.sas.com/

In particular, SAS offers many inexpensive training courses at its Boston facility:

http://www.sas.com/offices/NA/boston.html

For information about SAS on Athena, look at

http://web.mit.edu/sas/www/sas.html

Finally, there is a public mailing list for users to help each other with SAS questions. To add yourself to the mailing list on Athena, type the command

athena% blanche sasug -add $USER

1.5 Conventions

If you are reading this document as a FrameMaker document, the following conventions are used in the examples of SAS code.

italics indicate a value which you need to supply. The actual word or words in italics describe the value.

bold text is part of the SAS Language.

plain text is an example of a value. You may use the same name or a different one as you choose.

All SAS statements and procedures can take different options. Where options are specified in examples, they are either required or recommended ones.

2.0 Getting Started


There are three ways to run a SAS session: in window mode, in batch mode, and in interactive non-window mode. At MIT there is little reason to use the last mode, but both window and batch modes have advantages and disadvantages. Which mode you choose to use will probably depend on your personal preference and the task you are trying to accomplish.

2.1 Starting a SAS Session

SAS is available on the Sun platform. If you are sitting at an Athena workstation, you may run SAS in window mode on this platform by selecting SAS from the DASH menubar (SAS is on the Analysis and Plotting submenu of the Numerical/Math menu).

2.1.1 Running SAS in Window Mode

By default, invoking SAS when you are sitting in front of an Athena workstation will start in window mode. This mode has the benefit of providing pull-down menus and online help, but requires you to learn a little more about SAS in order to accomplish tasks.

In addition to starting SAS from the Dash menubar, you can enter the following commands at the athena% prompt:

athena% add sas

athena% sas &

To run a particular version, simply add the -version option:

athena% sas -version 6.11

After a short time, three windows will appear which allow you direct access to the base SAS system. With version 6.11, you will also see a fourth window, the SAS toolbar. This toolbar provides shortcuts to common commands. (SAS actually presents each window in turn as a "rubber band" outline on the screen; for each window, you need to move the mouse to indicate where you want to place the upper left corner of the window, then click the LEFT mouse button to have the window fully appear.) The three main windows form the SAS "Display Manager System":

TABLE 1.

----------------------------------------------------------
Window Title  Window Purpose                                
----------------------------------------------------------
SAS:OUTPUT    displays output of statements entered in      
              SAS:PROGRAM EDITOR window, or out             
              put from other SAS applications (except       
              high-resolution graphics, and all output      
              from SAS/INSIGHT, which go to other spe       
              cial-purpose windows)                         
SAS:LOG       displays system/error messages, including     
              start-up messages and messages about the      
              status of programs submitted in the           
              SAS:PROGRAM EDITOR window                     
SAS:PROGRAM   provides full-screen editing environment in   
EDITOR        which to create, edit, and submit SAS state   
              ments (this window is sometimes referred to   
              as the PGM window)                            
                                                            
----------------------------------------------------------

(SAS also creates another window titled xsassm, already iconified when it appears, that shows the status of the sas process and offers the option to terminate SAS.)

SAS also creates a directory in your home directory for storing some permanent data sets and information about your SAS configuration. On Sun workstations this directory is named ~/sasuser/sun4m. From within the SAS system, you may refer to files, data sets, and catalogs in this directory via the SASUSER library. (See Section 4.5 on page 10.)

2.1.2 Running SAS in Batch Mode

You may prefer to run SAS in batch mode on Athena. In this mode, you create a file containing your SAS program(s) and run SAS by typing

athena% add sas

athena% sas filename.sas &

where filename.sas is the text file containing your SAS program. When your SAS session completes, your output will be in the file filename.lst and the log of the run in filename.log. You must look at the log file to see whether your program encountered any errors.

Batch mode is appropriate if you are doing complicated data management, if you need to carefully document your procedures, or if you prefer not to learn about the SAS Program Editor or how to get around the SAS menu system. Running in batch mode also eliminates the overhead of setting up windows and gives you quick and direct access to the SAS programming language.

2.2 Getting Help

You can easily get help while running SAS in window mode. To start the online help system, click your LEFT mouse button on the Help menu at the far right end of any of the three main windows to see a list of help topics:

TABLE 2.

--------------------------------------------------------------
Topic            Displays New Window Containing...              
--------------------------------------------------------------
Extended Help    same as the SAS System help option when        
                 invoked from main windows, otherwise           
                 context sensitive help                         
Online Training  Online tutorial on SAS Fundamentals            
Keys             list of key/command bindings                   
SAS System       browsable hierarchy of all help topics (same   
                 as Extended Help)                              
Sample Pro       Information about online samples. Note that    
grams            not all of the samples are installed on Ath    
                 ena.                                           
SAS Compan       System Information particular to UNIX.         
ion                                                             
About...         Information about this installation of SAS     
                                                                
--------------------------------------------------------------

Note that the SAS on-line Help system has extensive reference material about the syntax of all the SAS procedures mentioned in this document. In particular, you might want to look at the Extended Help option Index as a first point of exploration if you are interested in finding out more about a procedure.

2.3 Ending a SAS Session

To end a SAS session in window mode, select the EXIT... menu option on the File Menu in the SAS:LOG or SAS:PROGRAM EDITOR window. You do not have to explicitly exit SAS when you run it in batch mode.

3.0 Writing Programs


This section very briefly describes the general elements of SAS programming. For more information about programming in SAS, consult the SAS programmers' documentation, in particular these books:

3.1 Parts of a SAS Program

A SAS program consists of one or more programming steps. Each step in turn consists of a set of one or more statements. Each statement is a individual instruction that usually starts with a keyword, and always ends with a semi-colon.

There are two types of steps:

To have SAS execute the program, you must also end the program with a RUN statement. (Actually, it is good practice to end each separate step with a RUN statement.)

You can include comments in a SAS program by enclosing the comments in the characters /* and */.

For example, here is a complete SAS program consisting of one DATA step and one PROC step:

data mydata;
infile '/mit/jruser/raw.data';
input name $ weight height;
run;
/* correlations of weight vs. height */
proc corr data=mydata;
var weight height;
run;

This program reads in a plain-text data file named raw.data, creates a temporary data set named mydata, then runs a correlation analysis on two of the variables of the data set. (This example program is included here simply to illustrate programming structure. To learn more about reading in files, working with data sets, and analyzing data, see other sections of this document, particularly Section 4.5 on page 10.)

Note that with the exception of quoted text, SAS is not case-sensitive as regards programming statements.

3.2 Creating a SAS Program

3.2.1 Window Mode

If you are running SAS in window mode, you may want to type your program directly into the PROGRAM EDITOR window. This window provides access to a full-screen text editor, but it is very different from either Emacs or vi on the Athena system. You may learn about the text editor by reading the SAS Language Reference, Chapter 19: SAS Text Editor Commands. The same information is available online by following the menus Help->Extended Help ->SAS Language->SAS Text Editor.

Because there is significant overhead in learning this Text Editor, you may want to use your regular text editor (e.g. Emacs) to create the file outside of SAS. To read it into the PROGRAM EDITOR window for execution, click the LEFT mouse button on the File Menu in the SAS:PROGRAM EDITOR window, select the Open submenu, then release the mouse button over the option titled Read File.... A dialog box appears in which you can enter the name of the file you created. If the lines all run together when SAS reads the file in, toggle the Autoflow option under the Options submenu of the Edit menu to OFF; this has SAS retain line breaks as in the file.

3.2.2 Batch Mode

If you run SAS in batch mode, you should type your SAS program using a text editor such as Emacs. Save the file and then run SAS as described in Section 2.1.2 on page 4.

3.3 Running a SAS Program

3.3.1 Window Mode

Once you have your program in the SAS:PROGRAM EDITOR window, you must submit it to SAS to be run. To do this, select the menu option Run on the Locals menu. The text of your program disappears from the SAS:PROGRAM EDITOR window and the results of the submission appear in the SAS:LOG window. You may view the results by scrolling the text using the scrollbar on the right hand side of the window. You must look at the SAS:LOG window to see whether your program ran correctly!

If there were no errors in your program and it produced textual output, the results are displayed in the SAS:OUTPUT window.

If the results in the SAS:LOG window indicate that there were errors in your program, you need to recall the text to edit it again. Selecting the Recall Text option on the Locals menu brings the program back into the editor window where you can make any necessary changes and re-run the revised program.

3.3.2 Batch mode

To run your SAS program in batch mode, simply specify the file containing your code on the command line:

athena% sas filename.sas &

When the program completes, you must check the log in filename.log (in other words, the same base filename as the file containing your SAS code plus the .log extension). If you do not look at this file, you cannot know whether your program ran correctly. If this file indicates that there were errors, make the corrections to your SAS program and re-run it.

Any output will be in the file named filename.list.

4.0 Working with SAS Data Sets


The SAS system deals with data in the form of a data set. To do almost anything in SAS, you must work with data sets. These sections explain:

4.1 Parts of a Data Set

A SAS data set is a collection of data logically arranged in a table-like structure. (That is, you may picture a dataset as containing rows and columns.) Columns of the table are referred to as variables (VAR); rows are called observations (OBS). A variable is a set of data with a common characteristic (e.g., weight, height, name). An observation is the set of all variable values associated with one specific data entity.

For example, in he data set in Table 3 on page 5, the variables are NAME, SEX, AGE, HEIGHT, and WEIGHT. Note that some variables are numeric while others are character-based. The observations correspond to each row of the data set. In this case, the observations are the set of variable values associated with exactly one student. (For more information on SAS variables, see Section 4.7 on page 11.)

TABLE 3.

--------------------------------------
OBS  NAME     SEX  AGE  HEIGHT  WEIGHT  
--------------------------------------
1    Alice    F    13   56.5    84      
2    Becky    F    13   65.3    98      
3    Gail     F    14   64.3    90      
4    Karen    F    12   56.3    77      
5    Kathy    F    12   59.8    84.5    
6    Mary     F    15   66.5    112     
7    Sandy    F    11   51.3    50.5    
8    Sharon   F    15   62.5    112.5   
9    Tammy    F    14   62.8    102.5   
10   Alfred   M    14   69      112.5   
11   Duke     M    14   63.5    102.5   
12   Guido    M    15   67      133     
13   James    M    12   57.3    83      
14   Jeffrey  M    13   62.5    84      
15   John     M    12   59      99.5    
16   Philip   M    16   72      150     
17   Robert   M    12   64.8    128     
18   Thomas   M    11   57.5    85      
19   William  M    15   66.5    112     
                                        
--------------------------------------

(This data set, named SASUSER.CLASS, is available to you through the SAS/ASSIST interface.)

4.2 Types of Data Set Variables

As noted, data set variables can have either numeric or character values:

If you do not specify the variable type when you create the data set, the variable is assumed to be numeric. If you are creating variables by reading data from a file, you can explicitly indicate that a variable should be considered a character variable by including the symbol $ after the name for the variable; see Section 4.7 on page 11 for more details.

SAS stores values differently depending on the variable type and length. Thus, for instance, given the way numeric variables are handled in SAS, it may be more efficient for you to specify a variable as character if you do not need to perform mathematical calculations on the values. Character values are limited to 8 characters unless you specify otherwise with the length statement. See the SAS Language Reference Chapter 9 for more details on the length statement.

4.3 Formats and Informats

You may further control the reading of, or displaying of data set variables using formats (displaying) and informats (reading). Formats and informats describe how to display data or interpret input. For example, there are datetime formats that allow you to read or print dates and times such as MMDDYYY. For more information, consult the SAS Language Reference Chapter 3.

4.4 About Data Libraries

SAS stores data sets in a data library, much as your operating system stores files in a directory. Data sets in a permanent data library are saved between SAS sessions (i.e., they are saved in an operating system directory and are available to you next time you start up SAS). Data sets in a temporary data library, in contrast, exist only as long as you are in the current SAS session (i.e., they are lost as soon as you exit SAS). You must name a data library when you create or access a data set.

4.4.1 Default Data Libraries

By default, SAS automatically creates two data libraries for you:

If you are using SAS for a course, your TA may have created a data library for use by members of the course. To access such a library, you usually need to attach the course locker from your athena% prompt first. Contact your TA for the location of the library and other specific instructions.

4.4.2 Naming Data Libraries

To refer to a data library other than SASUSER or WORK, you must assign a name to it. The LIBNAME statement associates a name with the operating system directory which contains (or will contain) your SAS files. The format of the LIBNAME statement is:

libname library-name `directory';

Library names must be 8 characters or less and may contain any standard keyboard characters. However, the first character must be a letter or an underscore.

Here are some examples of the libname statement. (Remember than SAS is only case sensitive with quoted text, so the last two examples are identical.)

libname mywork `/mit/25.555/dot';

libname STATS `/mit/dot/sas/stats';

libname sTaTs `/mit/dot/sas/stats';

Once you issue a libname statement in a SAS session, you may refer to SAS datasets in that library using the name you assigned. Remember, too, that if you name a directory path using the /mit pathname, the locker must be attached!

4.5 Naming Data Sets

You assign a name to a data set when you create it. Just like library names, data set names must be 8 characters or shorter and can contain any standard keyboard characters, including numbers and underscores. (The first character, however, must be a letter or underscore)

To name a permanent data set in SAS (a data set which is not in the WORK library), you specify the name of the library containing the data set. This is known as a library reference, or libref for short. Following the libref is a period, then the name of the data set itself:

libref.dataset

For data sets in your temporary library, you need only specify the data set name to refer to the data set:

dataset

For example, the following data set references are all in the correct format:

SASUSER.FITNESS

HOMEWORK._18.440a

PRODUCTS.LICENSED

WORK.MYDATA

MYDATA

SAS is not case-sensitive with respect to names of data sets or libraries: the names SASUSER, SASuser, and sasuser all refer to the same item.

4.6 Data Sets and Operating System Files

When you create a new data set in SAS, a file is created in an operating system directory. The association of a libref with an operating system directory determines exactly where this file is created. If you issue these statements in SAS:

libname mytest `/mit/dot/test';
data mytest.xy;
input x y;
cards;
1 2
3 4
;
run;

and then go to the directory /mit/dot/mytest outside of SAS, you'll see a file xy.ssd01. (1)

4.7 Creating a Data Set from an Operating-System File

You can create a new data set in SAS in many ways. The most common way involves the following two steps:

  1. Start with an operating system file containing your data. You may be given a file, or you may type the data into a file using a text editor such as Emacs.

  2. Start SAS and read the contents of that file into a SAS data set, either using a SAS program or through SAS/ASSIST.

SAS can read your data no matter how it looks in the file, but in the simplest case, data is either aligned in columns ("column" format) or separated by spaces ("list" format), as explained here. In either format, each row is assumed to correspond to an individual observation. (See Section 4.1 on page 8 for information on observations.)

4.7.1 Column Format

When your data is in column format (the suggested format), SAS assumes that all the data values for a particular variable are aligned in the same column position in the file. To read the data, you specify which specific columns each variable occupies in the file. In this format, missing values are notated by no value in the specified column. (In other words, a blank space.) For example:

-----------------------------------------
1  2  3  4  5  6  7  8  9  0  1   2  3  4  
-----------------------------------------
D  A  F  F  Y     D  U  C  K            5  
P  O  R  K  Y     P  I  G               3  
R  O  A  D        R  U  N  N  E   R     4  
H  E  W  E  Y                           3  
-----------------------------------------

(The line with numbers above is included only for reference to make clear what columns the characters are in. You should not include such a file in your actual data files!(2))

In column format, if the last columns in the file contains a string variable, make sure that all the rows are padded with enough blank spaces to fill the width of the field.

4.7.2 List Format

The other common format for raw data is called list format. When you data is in list format, SAS assumes that each data value is separated by one or more spaces or other special delimiter. For example:

-------------------------------------------
1  2  3  4  5  6  7  8  9  0  1  2  3  4  5  
-------------------------------------------
D  A  F  F  Y     D  U  C  K     5           
p  o  r  k  y     p  i  g     3              
r  o  a  d     r  u  n  n  e  r     4        
h  e  w  e  y     .     3                    
                                             
-------------------------------------------

(Note that there is a period in column 7 on this last line to indicate a missing string value. It would be a serious error to omit this period, for then SAS would read the numeral 3 as the last name and continue onto the next imput line, searching for a number.)

In this format:

4.7.3 The INFILE and INPUT statements

Once your data is in either of these two simple forms, it is easy to write a SAS program to read in the data. (If your data is in column format, you might also try the CREATE/IMPORT option in SAS/ASSIST, but the interface is rather non-intuitive.)

A complete programming step for reading in a data file would be of the following form:

data name; 
infile `filename';
input specs; 
run;

(Remember to include the semicolons at the end of each line!)

Here, name is a name to give the new data set within SAS. If you specify just a data set name (without a libref), the new data set will be put in your temporary data library (i.e., the library WORK). If you want the created dataset to be saved between sessions, be sure to give a complete name that includes the name of a permanent library into which to place the new data set (e.g., SASUSER.FOO). See Section 4.5 on page 10 for more details on naming data sets.

The option filename is the operating-system file pathname to your data file. This INFILE statement is very similar to the LIBNAME statement (Section 4.4.2 on page 9), except that instead of naming a directory, you name the full path to a file.

The option called specs are the specifications describing how to read in the data from the file into data set variables. The specifications include names for variables, whether the variable is a character variable or not, and special informats.

To read in variable data that is in column format, you need to specify the name you want to give to each variable, adding a $ after each variable made up of characters rather than numbers, and specifying the column(s) that each variable occupies in the source file. For example:

 input first $ 1-10 last $ 12-20 age 24;

To read variables in list format, you simply name the variables on the input line, adding a $ after each variable that is made up of characters instead of numbers. For example:

 input first $ last $ age;

Complete examples of programming steps would look like this.

Column Format:

data disney; 
infile `/mit/jruser/disney.data'; 
input first $ 1-10 last $ 11-20 age 22; 
run;

List Format:

data disney; 
infile `/mit/jruser/disney.data'; 
input first $ last $ age; 
run;

When this code is submitted to the SAS system (Section 3.3 on page 7), SAS reads in the data and creates a temporary data set called WORK.DISNEY. This data set will have three variables: two character variables named "first" and "last", and a numeric variable named "age":

TABLE 4.

-----------------------
OBS  FIRST  LAST    AGE  
-----------------------
1    DAFFY  DUCK    5    
2    PORKY  PIG     3    
3    ROAD   RUNNER  4    
4    HEWEY          3    
                         
-----------------------

If your data is not this simple, or you want further information, consult Chapters 2-4 of the SAS Language and Procedures, Usage document, or pages 377-389 (for the INFILE statement) or 393-422 (for the INPUT statement) of the SAS Language, Reference document (both Version 6, First Edition). Both of these documents are available in the Athena Consultants' Office (11-115).

5.0 Importing and Exporting Data


SAS stores permanent data sets in operating system files, but rather than storing data sets in a plain-text form, SAS stores data sets in a highly efficient special format (known as data set format) that varies depending on the type of workstation you are using.

In order to differentiate between data set files on different machine types, SAS uses different file extensions for the different architectures:

TABLE 5.

----------------------------------------
Machine     File Extension  Example       
Type                                      
----------------------------------------
Sun         .ssd01          disney.ssd01  
DECstation  .ssd02          disney.ssd02  
RS/6000     .ssd01          disney.ssd01  
SGI         not supported                 
            on Athena                     
----------------------------------------

Because the special storage format is machine-specific, you cannot create a data set on a machine of one type and read it on a machine of another type without first creating a version of the data set for the other machine type. For example, if you create a data set while working on a DECstation, you will not be able to read that data set on an Sun until you generate a version of the data set viewable on the DECstation. This is especially true if you wish to import data from a different platform or operating system.

5.1 Importing and Exporting under SAS Version 6

To create a data set on one machine ("A") and read it on another ("B") , you need to first convert it into an intermediate, or transport, format on A, then read that intermediate file into a data set on B. To create an intermediate data file, use PROC CPORT. To read an intermediate data file, use PROC CIMPORT.

  1. On machine A: To convert a SAS file into transport format use the SAS procedure CPORT. This procedure requires two arguments, the name of the data set to export and the name of a file to create in transport format. For example, the following SAS program creates a data file tdisney in transport format from the dataset disney:
libname tmpref `/mit/jruser/sasuser';
proc cport data=tmpref.disney file='/mit/jruser/sasuser/tdisney'; 
run;

  1. If you are not using shared file space to access the data on the two different machines, transport it to the remote machine.

  2. On workstation B: To convert a transport file into a SAS data set suitable for the machine you are now working on (i.e., to read the intermediate data form in on a different machine), use the SAS procedure CIMPORT. This procedure also requires two options, the name of the data set to create and the name of the transport file. For example, the following SAS program creates a data set on the new workstation with the data values from the old dataset:
libname tref2 `/mit/jruser/sasuser';
proc cimport ds=tref2.disney
infile='/mit/jruser/sasuser/tdisney'; run;

If you completed these two steps on machine A (a DECstation) and machine B (a Sun), you will have three files related to the original data set in /mit/jruser/sasuser:

 disney.ssd01 disney.ssd02 tdisney

You can now safely delete the transfer file (here tdisney) to help save disk space.

For more information about the CPORT and CIMPORT procedures, select the SAS Help menu option Extended Help, then choose Index, then the procedure of interest.

5.2 Importing Data Sets from Outside Athena

PROC CPORT and PROC CIMPORT only work under SAS version 6 or later. To import or export data to/from any version of SAS on any type of machine, use PROC COPY with the XPORT library engine.(3)

For example, suppose that someone ran PROC COPY on a distant machine and created an output file. You have that file now and named it /mit/jruser/sasuser/mm.dat. To create a SAS data set named mickey from this file, you might submit a SAS program along the following lines:

libname tref xport `/mit/jruser/sasuser/mm.dat'; 
libname outref v611 `/mit/jruser/sasuser/';
proc copy in=tref out=outref; 
select mickey; 
run;

After running this, you will have a file called mickey.ssd01 (if you are on an Sun) or mickey.ssd02 (if you are on a DECstation). Note that the XPORT engine requires a filename, not a directory name.

To export a data set, you would also use PROC COPY, but specify the library engines in the opposite order: libname tref xport `/mit/jruser/sasuser/mm.dat';

libname inref v611 `/mit/jruser/sasuser/';
proc copy in=inref out=tref; 
select mickey; 
run;

6.0 Printing


6.1 Printing Text

6.1.1 PROC PRINTTO

The procedure PRINTTO allows you to redirect text. It can be used in window mode to send output to a file instead of the OUTPUT window, but it can also be used in batch mode to redirect text from the .list file.

The syntax of PROC PRINTTO is:

filename outfile `your-output-file';
printto print=outfile new;
run;

where your-output-file is the full path to the file you wish to create. To cancel the redirection, type

proc printto;
run;
A complete program segment might look like this:
filename outfile `/tmp/sasoutput';
proc printto print=outfile new;
run;
/* Print a dataset to the output file*/
proc print data=sasuser.mydata;
run;
/* Set the output redirection back */
proc printto;
run;

You may then print the output file from your athena% prompt.

athena% lpr /tmp/sasoutput

6.1.2 Printing Text in Window Mode

If you are running SAS in window mode, you can easily save the contents of any window to a file. Simply choose the menu option File -> Save As -> Write to File and specify the file you wish to create. This menu option saves everything in the window to the file, so you may wish to clear out the window, (Edit -> Clear Text) run your program, and then save the lines. Again, use the Athena lpr command to print the file.

6.1.3 Printing Text directly to a Printer

You may use PROC PRINTTO to send output directly to an Athena printer. The only change you need to make is to the FILENAME statement. Rather than naming the path to an output file, you may tell SAS to pipe the output to a command. For example:

filename myoutput pipe `lpr -Pmyprinter';

where myprinter is the name of the Athena printer you wish to use.

A complete program could look like this

filename myoutput pipe `lpr -Php-test';
proc printto print=myoutput;
run;
proc print data=sasuser.test1;
run;
proc printto;
run;

6.2 Printing Graphics

Printing graphics is more complicated than printing text because if depends on your output device. This section gives you details on displaying graphics on an Athena workstation color monitor and printing graphics to a postscript printer. The syntax would be the same for all other types of output; only the details would change.

6.3 Graphics and SAS

Graphics in SAS can be high-resolution or low-resolution. Low-resolution graphics are pretty much text plots and are not discussed here. High-resolution graphics can be displayed on a workstation monitor or printed on a postscript printer.

The GOPTIONS statement allows you to configure various graphics options including a target graphics device and an output graphics device. The graphics output will be displayed on the output device and configured for the target device. For example, you could configure your output for a black & white printer but view it on the workstation monitor.

The syntax of the GOPTIONS statement for setting the target and output device is:

goptions target=targetdevice device=outputdevice;

The devices which you specify must be valid SAS graphics devices on Athena. Table 6 on page 12 lists the valid devices.

6.3.1 Displaying graphics on a workstation

To display graphics output on an Athena workstation monitor, use this GOPTIONS statement.

goptions device=xcolor;

6.3.2 Saving graphics to a file

If you want to save a graphic directly to a postscript file, you need to first set up an output device as described in "Printing Text directly to a Printer" on page 16. You also want to specify some other graphics options, making the resulting statements might look like this:

filename grafout `/tmp/myoutput';
goptions device=ps gsfname=grafout gsfmode=replace
gaccess=sasgastd;

This looks a little complicated, but here is what it means. The FILENAME statement associates a file reference or filref(here it is `grafout') with a UNIX file.. The filref needs to match the gsfname= option in the GOPTIONS statement.

The device=ps option says to format the output for monochrome postscript. You can use any appropriate postscript device listed in Table 6 on page 12. gsfmode=replace is an option which says to start a new file -- replace the old one if it exists. Finally, gaccess=sasgastd tells SAS to send the output to the location pointed to by the filref.

6.3.3 Printing Graphics to an Athena printer

To send output directly to a printer, you need to change the syntax of the FILENAME statement. The statements to configure output for a printer might look like this.

filename grafout pipe `lpr -Php-test';
goptions device=ps gsfname=grafout gsfmode=replace gaccess=sasgastd;

The FILENAME statement associates a file reference or filref(here it is `grafout') with a UNIX command to print. You, of course, need to specify your printer instead of hp-test. The logical name needs to match the gsfname= option in the GOPTIONS statement. The remainder of the graphics options are the same as described in Section 6.3.2 on page 17.

Finally, if you have already generated a graphic which is displayed on your workstation monitor, you can print it by choosing the menu option File ->Print... . If you did not specify a target= device in your goptions statement, you will be prompted for one. Again, choose any one of the postscript devices listed in Table 6 on page 12.

TABLE 6.

--------------------------------------------------
Device Name  Use for                                
--------------------------------------------------
XCOLOR       color workstation monitor              
PS           Monochrome Postscript, e.g. a printer  
PSCOLOR      Color Postscript                       
PSEPSF       Encapsulated Postscript                
PSLL         Postscript in Landscape mode           
PSLMONO      Monochrome Postscript with thin lines  
                                                    
--------------------------------------------------

7.0 Customizing SAS


When you run SAS on Athena, some defaults are set for you. For many users, these defaults are sufficient, but there may be a few things which you want to change temporarily for a single SAS session, or permanently for SAS session you start. This section gives an overview on the types of things you may want to customize, the different ways to customize SAS, and describes a few common customizations.

7.1 Changing the SAS Configuration

When SAS starts up, it looks for a file containing system configurations. This file is both machine and SAS version specific and therefore lives in the version-specific SAS locker(s). If you want to change any configuration options permanently, you can copy the system default file into your home directory and make the modifications there. A personal configuration file will override the system default one.

To copy the default configuration file, first make sure that you have the version-specific locker attached. It is attached automatically when you run SAS, or you can attach it by hand. The locker will be named according to the convention

sas_vX.XX

where X.XX is the SAS version. For example, the current version lockers are sas_v6.11 (Sun) and sas_v6.09 (Sun) and sas_v6.07 (DECstation). You can attach the locker by typing a command like this:

athena% attach sas_v6.11

Next, copy the system default file into your home directory. The configuration file is named with a version specific name of the format

config.sasXXX

where XXX is the same number as above. In other words, the locker name uses a period to separate the major and minor version numbers, but the config.sas file does not.

Using the locker you just attached, type a command like this:

athena% cd

athena% cp /mit/sas_v6.11/distrib/@sys/sas/config.sas611 .

(The command should be typed on a single line.) You may now edit the file config.sas611 with your favorite editor.

IMPORTANT! If you do copy the system default file, please remember to get a new copy if and when SAS is upgraded on Athena.

7.2 Using command line options

Some of the configuration options named in the config.sas file can be specified on the command line. Command line options override any corresponding ones in the config.sas file. For example, to redirect the WORK data library for a single SAS session, you can type

athena% sas -work /var/tmp/dot

You can also redirect the SASUSER data library with a command line option.

7.3 Running SAS statements at Start-up

If you create a file in your home directory named autoexec.sas, you can automatically execute commands every time you start SAS. Just as with the config.sas file, there is a system default autoexec.sas which you should use as a starting point. Copy it to your home directory by attaching the version locker (See Section 7.1 on page 19 for details), and typing the command

athena% cp /mit/sas_v6.11/distrib/@sys/sas/autoexec.sas ~

(Of course, you may need to specify a different version locker!) You may now edit this file and add sas statements to do things such as automatically assign librefs.

7.4 Finding Disk Space for your SAS Programs

If you are running SAS sitting at an Athena workstation, you have 200-300 meg of disk space accessible to you for scratch work on the local hard disk. You can access this space outside of SAS by looking in the filesystem directory /var/tmp. Within SAS, any temporary datasets you create in the WORK data library will use this disk space. (The default assignment of the WORK libref is /var/tmp.)

8.0 Introduction to the SAS Text Editor


If you run SAS in window mode, you will probably need to know a little bit about the SAS Text Editor. This is the editor which you use when you edit programs in the PROGRAM EDITOR window.

8.1 Prefix Commands

This editor uses something called line commands. Line commands are single-character and double-character commands which you type in the prefix area on each line. (The prefix area is that area which is marked by the 5-digit line numbers.)

Single character commands apply to a single line while double-character commands apply to blocks of lines between command markings. For example, a single `d' in the prefix area deletes a single line, while a double `dd' marks the beginning and end of a block of text to delete. To enter a line command, type the letter or letters in the prefix area and hit the return or enter key.

Single character line commands may also take a number parameter indicating that the command should be repeated <N> times. For example, d5 deletes 5 lines and i10 inserts 10 lines. Table 7 on page 14 lists some of the common line commands.

TABLE 7.

-----------------------------------------------------------
Command  What it does                                        
-----------------------------------------------------------
d        Delete a line of text                               
dd       Delete a block of text                              
m        Move a line of text. Once you hit return, you'll    
         be prompted for a new location for the line. Use    
         the line command `a' or `b' to mark a location      
         after or before another line.                       
mm       Moves a block of text                               
c        Copies a line of text. Use `a' or `b' to mark the   
         new location.                                       
cc       Copies a block of text                              
i        Inserts a line after the current line               
ia       Same as i                                           
ib       Inserts a line before the current line              
cols     Opens up the display and shows a temporary line     
         which marks the column numbers. To remove           
         this line, use the d line command.                  
-----------------------------------------------------------

8.2 Inserting Text

By default you are in overwrite mode. To toggle between overwrite and insert modes, use the command C-x (Control-X).

8.3 For more Information

The SAS Text Editor is described in the online help and in Chapter 8 of the SAS Language Reference.

Appendix A config.sas611


This is a copy of the config.sas611 file. You may access it by typing

athena% attach sas_v6.11

athena% more /mit/sas_v6.11/distrib/@sys/sas/config.sas611

/*
 * This file, config.sas, holds default configuration options
 * for the SAS System.  These options are overridden by options on the
 * command line, or options specified through the SAS611_OPTIONS
 * environment variable.
 *     
 */
/*
 * -maps     specifies the pathname of the map datasets used by PROC GMAP.
 */
-maps !SASROOT/maps
/*
 * -msg      specifies the directory where the SAS System will search
 *           for the files containing the text for all error messages
 *           and notes.  These messages are stored in an internal format.
 */
-msg !SASROOT/sasmsg
/*
 * -news     specifies the name of a text file that will automatically
 *           be displayed in the log when SAS is invoked.
 */
-news !SASROOT/misc/base/news 
/*
 * -sasautos establishes the path(s) to director(ies) for automatic
 *           macro definitions to be searched by the macro facility when
 *           an unknown macro is referenced.
 */
-sasautos !SASROOT/sasautos
/*
 * -sashelp  specifies the pathname for the directory containing on-line 
 *           help and menu screens for the SAS System.   
 */
-sashelp !SASROOT/sashelp
/*
 * -sasuser  specifies the pathname for the directory used by the SAS
 *           System as a default place to store files, such as the SAS
 *           user profile catalog.  See your SAS System documentation
 *           for more information.
 */
-sasuser ~/sasuser/sun4m
/*
 * -work     specifies where to create the SAS work library.  This
 *           library is temporary and any SAS data sets created there
 *           will be deleted when the system terminates.  The unique name
 *           `SAS_workANNNN' is assigned to each SAS work library.  `A' is

 *           some letter and `NNNN' is the hexadecimal representation of the
 *           process ID of the SAS process.
 */
-work /var/tmp
/*
 * -sasscript   specifies the location to search for SAS/CONNECT scripts.
 */
-sasscript !SASROOT/misc/connect
/*
 * -dms      specifies that you are running SAS in Display Manager mode.
 */
-dms
/*
 *
 * -memsize limits the amount of memory that will be allocated by the
 *           SAS System.
 */
-memsize 32m
/*
 *
 * -sortsize limits the amount of memory that will be allocated during
 *           sorting operations.
 */
-sortsize 16m
/*
 *  Default windowing system to use.
 */
-fsdevice x11.motif
/*
 *   -helpenv  specifies that native help should be used when help is 
 *         invoked.
 */
-helpenv helplus
/*
 *   -helploc  specifies the location of the native help files for helplus.
 *         You would have to specify `-helpenv helplus' to use those files.
 */
-helploc !SASROOT/X11/native_help
/*
 *   -samploc  specifies the location of the sample files for helplus.
 */
-samploc !SASROOT/X11/native_help
/*
 * -path     specifies the search path that the SAS System will use
 *           to find the dynamically loaded modules.  Each -path
 *           specification indicates one directory.  They will be
 *           searched in the order in which they are given.
 */
-path !SASROOT/sasexe/base

-path !SASROOT/sasexe/graph
-path !SASROOT/sasexe/stat
-path !SASROOT/sasexe/fsp
-path !SASROOT/sasexe/af
-path !SASROOT/sasexe/insight
-path !SASROOT/sasexe/ets
-path !SASROOT/sasexe/iml
-path !SASROOT/sasexe/connect
-path !SASROOT/sasexe/or
-path !SASROOT/sasexe/qc
-path !SASROOT/sasexe/dbi
-path !SASROOT/sasexe/english
-path !SASROOT/sasexe/fsc
-path !SASROOT/sasexe/gis
-path !SASROOT/sasexe/image
-path !SASROOT/sasexe/lab
-path !SASROOT/sasexe/nvi
-path !SASROOT/sasexe/pub
-path !SASROOT/sasexe/share
-path !SASROOT/sasexe/trader
-path !SASROOT/sasexe/toolkit
-path !SASROOT/sasexe/spectraview
-path !SASROOT/sasexe/unixdb
-filelocks none
-editcmd /usr/athena/bin/emacs
-lptype bsd

Appendix B autoexec.sas


Here is a copy of the default autoexec.sas file. You may look at it by typing

athena% attach sas_v6.11

athena% more /mit/sas_v6.11/distrib/@sys/autoexec.sas

libname gdevice0 v611 `/mit/sas_v6.11/Athena/sun4m_54';

Footnotes

(1)
This assumes that you are running SAS on a Sun. Creating a dataset on a DECstation would result in a file named xy.ssd02.
(2)
You can turn on column mode in Emacs by typing the command M-x set-variable column-number-mode t. If column mode is on, the current column number will be displayed in the status line.
(3)
Library engines are explained in Chapter 6 of the SAS Language Reference.