You have reached an Archive Page on the CCTR web server!

This web page is no longer being updated, and the information may be outdated or inaccurate. If you have reached this page from a link on another page, please inform the CCTR web maintainer. If you need help finding information regarding CCTR, please contact us at ops@cctr.umkc.edu.

CCTR SAS


| Site | Docs | Ref | Resources | Community   | FeedBack |
| Mail | Web | Software | Classes | FAQs |
|ACCESS |DIALUP |DOS |EXCEL |FOX |HTML |MAPLE |POWERPT |SAS |
|SPSS |WINDOW |WORD |WP |WWW-HTML |WWW |XWIN |

Introduction to the SAS system:
-------------------------------

SAS is statistical software developed to perform data analysis. Its
capabilities range from language translation to data management and
statistical application. SAS is a set of many interrelated software products,
at the heart of those programs is Base SAS which contains SAS supervisor which
communicate and work with the operating system, the DATA step language
compiler, input/output access method, a number of SAS procedures that take care
of complex computing tasks, and other services that are required for the SAS
job.

SAS Files:
----------

For SAS to be able to analyze data, the data have to be in a format that is
readable by SAS. The data have to be stored as a SAS file ready to be accessed
by SAS software using any of the methods. Furthermore, SAS files that are created by SAS/Access software and
contain data that the interface engine may use to implement an access view are
called Access descriptor files. Another kind of SAS file is Stored programs
which contain compiled code produced by a data step program. SAS Catalogs are
a kind of SAS file that contain one of the many form catalog entries. All these
files can be stored in SAS Libraries

The SAS Job:
------------

There are two types of SAS job step: DATA steps, where data are read,
stored, rearranged, and written in a way the user may specify using the DATA
step language, and PROCedure Steps which start a certain SAS service. Spacing
is not important in SAS and the file could contain extra spacing within it.
We can distinguish between two types of statements, executable, and
non-executable. Most DATA step statements are executable which means that the
compiler is ordered to prepare code for an immediate action. Non-executable
commands such as TITLE, DROP, KEEP, and LABEL are not associated with a
specific demand for immediate computational action. Some commands are only
meaningful when used under another command, Commands such as SET, MERGE,
INFILE, FORMAT, LABEL, TITLE, LIBNAME, and OPTIONS are examples of such
command. There is also what is called statement modifiers or sometimes they are
referred to as OPTIONS, which if present in a certain context will tell SAS to
make specific refinements to the way it carries out the instructions in the
statement.

For Example:

TABLES COUNT;
TABLES COUNT / NOPERCENT;
or
INFILE FILE1;
INFILE FILE1 END=AGE;

In the example we modified the first statement by using the keyword
NOPERCENT, and similarly we modified the second statement by using END=VARIABLE
NAME. SAS names could not start with numbers, should be 8 characters long or
less, should not contain any non-alphanumeric characters except the underscore
(_), and there should be no spaces included in the name. The following Names
are invalid:

PREDICTABLE (more than 8 characters)
12AGE (cannot start with numbers)
THAT.ONE (contains a non-alphanumeric character".")
THIS ONE (contains space)

Statement Labels could be added by starting the statement with the label
followed directly with a fixed post colon":", for Example,

THIS: INPUT X Y Z;

Operators (both numeric and character) could be used in SAS also, for example
on numeric operators we have, + is for adding, - is for subtracting, / is for
dividing, and * is for multiplication. For character we have, LT(<) for less
than, GT() for greater than, EQ(=) for equality, NQ(^=) for non-equality,
LE (=<) is less than or equal to. The following table should aid with respect
to the different operators:

SAS DATA STEP LANGUAGE OPERATORS

  
SYM       ALT           Definition           Example  Result 
---       ---           ----------           -------  ------                   
                                                                               
+       (prefix)    Makes Value Positive        +2       2 
-       (prefix)    Makes Value Negative        -2      -2 
**      Exponential                             3**3     27 
*       Multiplication                          3*3      9 
/       Division                                4/2      2 
+       Addition                                4+4      8 
-       Substraction                            4-4      0 
<       Maximum                                 5<10     10 
<       Minimum                                 5<10     5 

Comparison Operators                                                           
--------------------

=       EQ           Equal                      3+4=7    1(true) 
^=      NQ           Not Equal                  3+4^=    0(false) 
<       LT           Less Than                  3+4<7    0
        GT           Greater Than               3+47     0 
<=      LE           Less Than or Equal to      3+4=<7   1 
=       GE           Greater Than or Equal to   3+4=     1 
none    IN           List Membership            3+ IN(6,7<8) 0 
        SAS also have DATA step language Functions that are specified with 
basic operations, and are a SAS function name followed by one or more function 
arguments in parentheses.  

For example: 
 
ROUND (387.26,.1)       which equals 387.3.  

The following table have a list of some of those Functions: 
 
SOME SAS DATA STEP LANGUAGE FUNCTIONS 
-------------------------------------

Numeric Functions

Purpose                         Example                 Result 
-------                         -------                 ------

Round to the nearest unit       ROUND(27.3,.5)          27.5 
Closest lower integer           FLOOR(18.9)             18 
Absolute Value                  ABS(-83)                83 
Modular remainder               MOD(16.3)               1 
Summation                       SUM(1,2,3,4,5)          15 
Average                         MEAN(1,2,3,4,5)         3 
Maximum                         MAX(1,2,3,4,5)          5 

Character Function
                                                             
Locate Character                INDEXC('HELLO','L')     3 
Locate String                   INDEX('HELLO','LO')     4 
Find nth word                   SCAN('HELLO THERE',2)   2 
Find Substring                  SUBSTR('ABCDE',2,3)     BCD 
Uppercase                       UPPER('Pqrst)           PQRST 

In SAS the user can add any comment that he want to show on the output
files. The Comment statement must start with an astrict and end with the SAS
semi-colon

* This is a COMMENT;

A delimited comma can also be added to enable the user to use characters like
the semi-colon and it should start with (slash-astrict) and should end with
(astrict-slash), for example,

/*This is a delimited Comment; yes, it ! is*/

The Following are the Statements used in the DATA step:
-------------------------------------------------------

ABORT:  Used to stop the execution of SAS job Immediately, 
        format : IF_ERROR_THEN ABORT; 
ARRAY:  Used to enable the processing of many variable the same way, 
        format : ARRAY ITEM(|) $ 12 X1-X10; 
BY:     Used to control the operation of a SET, MERGE, or UPDATE Statements, 
        format : BY MONTH NONSORTED; or BY STATE CITY MONTH;  
CALL:   Used to call a routine, 
        format : CALL SYMPUT(macro variable, SAS variable); 
CARDS:  Used to note that the data is after it. 
DATA:   Used to begin the data set and assign a name for the data set, 
        format : DATA EXAMPLE; 
DELETE: Used to stop the processing of a current observation, 
        format : IF GRADE <^ THEN DELETE; 
DO:     Used to specify that the statement following the DO are to be executed 
        as a unit until  a matching END Statement appears, 
        format : IF X=Y THEN DO; 
                 X=X+!; 
                 PUT X; 
                 END; 
                 OUTPUT; 
DROP:   Used to specify variables that are not included. 
END:    Used to indicate the end of a DO statement. 
ERROR:  Used to print a message on the SAS log and sets the automatic SAS  
        variable_ERROR_to 1, 
        format : _ERROR_=1; 
FILE:   Used to define the current output file, 
        format : FILE EXAMPLE; 
FORMAT: Used to associate output formats with variables in a DATA step, 
        format : PROC FORMAT; 
                 VALUE SEXFMT 1=Male 2=Female; 
                 DATA ALL; 
                 INPUT NAME $ SEX@@; 
                 FORMAT SEX SEXFMT.; 
GO TO:  Used to tell SAS to jump to a different Statement, 
        format : If 1<=X<=5 THEN GO TO OK; 
IF:     Used when you want to execute a SAS statement for some of the 
        observations. 
INFILE: Used to identify a non-SAS file on a disk or  
tape. 
INFORMAT: Used to specify a default informat for variables 
        listed in an input statement. 
INPUT:  Used to read values into variables from input data lines. 
KEEP:   Used to specify the variable that are to be included in any SAS data 
        sets being created. 
LABEL:  Used to give labels to variables. 
LENGTH: Used to specify the number of bytes for sorting values of variables in 
        each data set being created. 
LINK:   Used to tell SAS to jump to another statement in the same DATA step and
        begin executing statements from that point on. 
LIST:   Used to list on the log file the input data lines for the observation 
        being processed. 
LOSTCARD: used to resychronize the input data when SAS encounters a missing 
        record in data with multiple records per observation. 
MERGE:  Used to join corresponding observations from two or more SAS data sets 
        into single observation in a new SAS file. 
MISSING: Used to declare that certain values in the data are missing. 
NULL:   It does not perform any task. 
OUTPUT: Used to tell SAS to write the current observation to the data set being
        created. 
PUT:    Used to write output lines. 
RENAME: Used to give variables a new name. 
RETAIN: Used to reatain a variable value from previous execution. 
RETURN: Used to stop SAS from executing and to go back to the beginning. 
SET:    Used to tell SAS to read observations from different data files. 
STOP:   Used to tell SAS to stop processing a DATA step. 
UPDATE: Used to combine observations from two SAS data sets in a manner similar
        to the MERGE statement. 

The following is an example of a SAS program file.
--------------------------------------------------

This file was created in CCTR by using the EVE editor as follows:
$EVE Example.SAS

type in the following program

********A SAS Program********
DATA Example;
THAT: Input Name $ Height Weight Age;
*This is a comment;
/*This is a delimited comment;yes it is !!!*/
Cards;
Joey 62 189 23
Frannie 54 121 20
Robby 59 172 19
Joy 51 108 17
Run;
Proc print data= example;
run;
proc means data= example;
Title1 'Averages of Data';
title2 'Example';
proc plot data= example;
plot height*weight;
title 'PLOTTTTTT1';
proc plot data= example;
plot height*age;
title 'plottt2';

Run;
********************

In the previous program we used the statement command to give our data a name
“Example”, and the INPUT statement to identify the variablnames. CARDS is the
statement that tells SAS that the data is next. After we entered the data, we
are ready to start different procedures or “PROC”. In the example we ditwo
procedures: PRINT which give us a printout of the data, and MEANS which give us
a printout of the averages for the data example. All statements ends with a
semicolon”;” and this is mandatory iSAS.

      If we run the previous program by using the batch command CCTR by typing 
$ runsas Example.SAS, we get the following two files: 
 
1.  The Log file which should be under Example.log  
      
The SAS System                           
  
 NOTE: Copyright(c) 1989 by SAS Institute Inc., Cary, NC USA.  
 NOTE: SAS (r) Proprietary Software Release 6.09  TS027 
       Licensed to UNIVERSITY OF MISSOURI - KANSAS CITY, Site 0007049001. 
 NOTE: Running on DEC Model 3000 - M600 Serial Number 80000000. 
  
  
       Welcome to the SAS Information Delivery System, Version 6.09 
       
=================================================================== 
  
  Computing Services is now offering the full slate of SAS products. That 
  includes Base SAS, AF, Assist, Calc, Connect, Graph, English, ETS, FSP, 
  IML, Insight, Lab, OR, QC, and Stat.  We also licensed the six Computer 
  Based Tutorials.  Give the Tachyon command $ SASTUTOR to start those 
  tutorials.   
     For a short description of each product, give the VMS command 
              
        $ TYPE/PAGE PUBLIC:SAS-PRODUCTS.LIST 
  
  Our local SAS support representative is Deborah Wall.  She can be 
  reached either at 235-1184 or username wall@vax1.umkc.edu.  
 1          DATA Example; 
 2          THAT: Input Name $ Height Weight Age; 
 3          *This is a comment; 
 4          /*This is a delimited comment;yes it is !!!*/ 
 5          Cards; 
  
 NOTE: Unreferenced label defined: THAT. 
 NOTE: The data set WORK.EXAMPLE has 4 observations and 4 variables. 
 
 10         Run; 
 11         Proc print data= example; 
 12         run; 
  
 NOTE: The PROCEDURE PRINT printed page 1. 
 
 13         proc means data= example; 
 14         Title1 'Averages of Data'; 
 15         title2 'Example'; 
 
 NOTE: The PROCEDURE MEANS printed page 2. 
 
 16         proc plot data= example; 
 17              plot height*weight; 
 18         title 'PLOTTTTTT1'; 
  
 NOTE: The PROCEDURE PLOT printed page 3. 
  
 19         proc plot data= example; 
 20              plot height*age; 
 21         title 'plottt2'; 
 22          
 23         Run; 
  
 NOTE: The PROCEDURE PLOT printed page 4. 
 NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414. 
 
        The log file is basically a description of the interpretation of the 
different data steps and proce
dures that SAS found in the file we ran. The 
importance of the Log file is mainly that it tells the researcher about any 
errors found or warnings that might be a reason for  alarm. 

2.  The output file which is found under Example.Lis 
 
1                                                           
The SAS System     10:21 Monday,  May 22, 1995   1 
  
OBS    NAME       HEIGHT    WEIGHT    AGE 
---    ----       ------    ------    ---
 1     Joey         62        189      23 
 2     Frannie      54        121      20 
 3     Robby        59        172      19 
 4     Joy          51        108      17 
1                                                          

Averages of Data                             
                                                               
Example 
-------
                                  
Variable  N          Mean       Std Dev       Minimum       Maximum         
------------------------------------------------------------------- 
HEIGHT    4    56.5000000     4.9328829    51.0000000    62.0000000 
WEIGHT    4   147.5000000    39.0939040   108.0000000    189.0000000 
AGE       4    19.7500000     2.5000000    17.0000000    23.0000000 
------------------------------------------------------------------- 
 
PLOTTTTTT1
----------
  
Plot of HEIGHT*WEIGHT.  Legend: A = 1 obs, B = 2 obs,  
   
  HEIGHT |
         |                                                    A
      62 +   
         | 
      60 + 
         | 
      58 + 
         | 
      56 + 
         | 
         | 
      54 +                             A 
         | 
         | 
      52 + 
         |            A 
      50 + 
         | 
         --------+------------+------------+------------+------------+--------- 
           100          110          120          130          140          150          160          170                                             WEIGHT 
  
 
                                                                               
                                                       
                                                             
plottt2                                 
                                       Plot of HEIGHT*AGE.  
Legend: A = 1 obs, B = 2 obs, etc. 
         HEIGHT | 
                | 
             62 +                                                          A 
                | 
             60 + 
                |                                    A 
             58 + 
                | 
             56 + 
                | 
             54 +                                                     A 
                | 
             52 + 
                |  A 
                -----------+----------------+----------------+----------------+------ 
                  17               18               19               20               21               22               AGE 


The output file is a list of all the results of the calculations that
were requested. SAS as could be seen from the latter example is a very powerful
programming language that is easy to understand and perform. It is true that a
very simplistic example was used however, with a little extension on the
program we can do almost everything. The following are the different
statements used in the PROC step:

BY, CLASS, DROP, FORMAT, FREQ, ID, KEEP, LABEL, MODEL, OUTPUT, PROC, VAR,
WEIGHT

The Following are Features for both, the DATA step and the PROC step:

CLEAR, CMS, COMMENT, ENDSAS, HELP, %INCLUDE, %LIST, MACRO, OPTIONS, PAGE, %PUT,
RUN, %RUN, SKIP, TITLE, TSO, X.
As in the example SAS is a very easy to use software. Even thought, SAS can
offer much more than that of the example SAS files are only an extension of
our example. There is a SAS TUTOR available on UMKC's CCTR and you can access
it by typing SASTUTOR on the dollar prompt.


WebMaster@umkc.edu

Information Services, Central Computing
University of Missouri Kansas City