Some Notes on Using SAS via SAS EDITOR

(j.h. and a.n. 97.06.07)

See also notes prepared by Marielle Olivier, available on shelf in computer laboratory

SAS is organized around 3 windows Typical sequence is to Before resubmitting, you will wish to 'clear' the LOG window; you may also wish to clear the OUTPUT window, so that output from previous submissions in the same session do not accumulate and confuse.

A SAS Program

A SAS 'program' (at least for a beginning user, working on a small dataset) is likely to consist of the following: You can save the 'program' for future use/modification. Do so from the file menu when in the PROGRAM window. Many users use the suffix '.sas', to designate a file containing sas statements and requests for procedures to be run.

The DATA step -- overview

There are a number of ways to set up the data for use in one or more PROCS.

The DATA step -- in more detail

EXAMPLE of DATA step followed by SORT and several procedures;

DATA alberta;

INFILE 'alberta.dat';

INPUT id_no age gender height weight;

      bmi = weight / height**2;    * **2 is same as 'to power of 2';
      
      if age >= 11 and age <= 15; * careful with 'ands' and or's' ; 

PROC SORT; BY gender;    * sorts the dataset 'alberta' by gender;
                         * otherwise leaves dasaset contents as is;
RUN;

PROC MEANS;

   var height weight;
   BY gender;            * repeats procedure for each gender;
                         * must have used SORT beforehand;

PROC PLOT FORMCHAR='-----------'; /* formchar supplies  character */
                                  /* for borders of plot          */
   PLOT weight*height = gender; 
                         
                         * uses values of gender as symbol;
RUN;

PROC PLOT;
   PLOT Y1*X = '1' Y2*X='2' / OVERLAY; 
                         
                         * puts both plots on same graph ;
                         * using the symbols 1 and 2 respectively;                         
PROC GLM;
   MODEL weight = height ;
   BY gender;
      
RUN;

PROC REG;
   MODEL weight = height; * like GLM but uses continuous x's only ;
   BY gender;             * does not allow 'class' variables      ;
                          * does not produce Type I and III SS    ;                 
                  
DATA males;           * creating a new dataset;

  SET alberta;        * reads observations from existing dataset ;
                      * created earlier in session, or stored as ;
                      * a permanent dataset, ...                 ;
                       
  IF gender = 0;      * allows only those with gender = 0 to be  ;
                      * taken into new dataset                   ;

RUN;

DATA females;         * creating yet another...                  ;
                      * alberta and males still exist and are    ;
                      * available to all PROCS                   ;
SET alberta;

IF gender = 1;

RUN;

A PROGRAM TO ILLUSTRATE SOME SELECTED PROCEDURES AND FEATURES OF SAS : MEAN, PLOT, GLM, REG, OUTPUT, MERGE, OVERLAY, BOX

OPTIONS LS=65 PS=65;

DATA a;

  INFILE 'a:kkm5_8.dat';

  INPUT salary gpa;

  ID = _N_;

RUN;

DATA f2; SET a;

PROC MEANS;

PROC PLOT; PLOT salary * gpa;

PROC GLM;
 MODEL salary = gpa;

PROC REG;
 MODEL salary = gpa/CLM CLI;  /* CI for mean, individuals */
 OUTPUT  OUT = temp 
         PREDICTED = p
         L95M=lm U95M=um L95=li U95=ui;
RUN;

DATA f3; SET temp;
ID = _N_;

RUN;

DATA f4; MERGE f2 f3; BY id;

RUN;

DATA f5; SET f4;


PROC PLOT;
  PLOT salary*gpa='s' p*gpa='p'
      lm*gpa='*'  um*gpa='*' li*gpa='+'  ui*gpa='+' / OVERLAY BOX;

RUN;

General comments

If you minimize the PROGRAM Window before you run the program, you will be able to see the LOG window and tell by the colours of the messages whetehr your program has been successful!!

OUTPUT and LOG windows

You can save the contents of these windows:- use the 'save' or 'save as' command in the file menu.

You can customize the width (no of characters accross) and height (number of lines down) of the OUTPUT pages... using the OPTIONS statement at the beginning of the program...

PAGESIZE (or PS for short) # of lines on page
LINESIZE (or LS for short) # of character spaces accross the page

e.g.

OPTIONS LINESIZE = 75 PAGESIZE = 60;    /* 60 lines of 75 characters */

If you save the OUTPUT or LOG file and then open it in a wordprocessor, better to use a MONO-spaced font such as COURIER ... otherwise tables and plots will not line up.