SAS Examples

Instructor:  Joshua D. Naranjo
E-mail: joshua.naranjo@wmich.edu
Phone: (269)387-4548
Office: 5507 Everett Tower
How to Input Data into SAS

There are many ways to input data into SAS. We will discuss three ways here that are useful for class.

  1. Reading instream data
                   
        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
        ;                                        
    
  2. Reading data from an external text file

    To read a text file use an INFILE statement before the INPUT statement. The structure of the INPUT statement does not change.

        DATA homes;
               INFILE 'D:\Stat6620\Data\homedata.txt';
               INPUT price sqft age;
               priceT=price/1000;
        RUN;
    
  3. Reading data from the Internet

    When a data file is accessible over the Internet, use a FILENAME statement to assign a nickname to the file, then use the INFILE statement as before.

        FILENAME tmpname URL "http://www.stat.wmich.edu/naranjo/sas/homedata.txt";
        DATA homes;
               INFILE tmpname;
               INPUT price sqft age;
               priceT=price/1000;
        RUN;
    

 

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