SAS Examples

Instructor:  Joshua D. Naranjo
E-mail: joshua.naranjo@wmich.edu
Phone: (269)387-4548
Office: 5507 Everett Tower
A simple SAS program

  1. A SAS program typically has a DATA step and a PROC step.
  2. For example
                   
              DATA homes;                              
                     INPUT price sqft age;             
                     priceT=price/1000;                
                     DATALINES;
              205000 2650 13
              215000 2664  6
              215000 2921  3
              199900 2580  4
              190000 2580  4
              180000 2774  2
              156000 1920  1
              137500 1837  4
              127000 1880  8
              125000 2150 15
              123500 1894 14
              117000 1928 18
              ;                                        
    
              PROC PRINT DATA=homes;                  
              RUN;                                   
    
              QUIT;
    
    Comments:
    • The DATA statement starts with the SAS keyword `DATA'. It tells SAS that you want to create a data file with a name that you specify, i.e. `homes'.
    • The INPUT statement starts with the SAS keyword 'INPUT'. It tells SAS the names of the variables that are going to be read. Here, you want to read values for three variables: `price', `sqft', and `age'.
    • In the DATA step, you may create variables that are functions of other variables.
    • The DATALINES statement tells SAS that the lines of data will follow.
    • The semicolon tells SAS the end of the lines of data.
    • The PROC PRINT statement starts the PRINT procedure. The optional DATA keyword tells SAS what data set to print.
    • The RUN statement executes previous code, in this case PROC PRINT.
    • The QUIT statement produces output, and closes open files.

 

Department of Statistics
3304 Everett Tower
Western Michigan University
Kalamazoo MI 49008-5152 USA
(269) 387-1420 | (269) 387-1419 Fax
stat-webmaster@wmich.edu