rssunt.gif (12308 bytes)


Introduction to SAS - Examples

Data | Procedures | Examples | Download | Exercise

Creation date: 7/17/98
Author: Karl Ho

Example 1

Data;
input x y z @@;
cards;
1 2 3 4 5 6 7 8 9
;
run;

Example 2

FILENAME DATAIN 'A:\COUNTRY.DAT';
DATA COUNTRY;
	INFILE DATAIN;
        INPUT DEC 1 ID 2-4 NAME $CHAR26. SSCODE 31-33
              CONTIN $ 34-35 DODEV 36 POPULATE 37-43
              AREA 44-49 GNP 50-56 MILEXPED 57-64 .1
              PEDEXPED 65-71 .1;
PROC PRINT DATA=COUNTRY;
RUN;

Example 3

TITLE 'SAS SAMPLE - COUNTRY DATA';
LIBNAME PROJECT1 'A:\MYDATA';
DATA PROJECT1.COUNTRY; 
    ARRAY MISSING GNP MILEXPED PEDEXPED;
    infile 'a:\country.dat';
    input dec 1 id 2-4 name $char26. sscode 31-33
          contin $ 34-35 dodev 36 populate 37-43
          area 44-49 gnp 50-56 milexped 57-64 .1
          pedexped 65-71 .1;
    label name   = "COUNTRYS' NAME"
             CONTIN  = 'CONTINENT'
             DODEV   = 'DEGREE OF DEVELOPMENT'
             GNP     = 'GNP IN MILLIONS OF DOLLARS'
             MILEXPED= 'MILITARY EXPENDITURE IN MILLIONS OF $'
             PEDEXPED= 'PUB. EDUCATION EXPENDITURE IN MIL. $';
    DO OVER MISSING;
       IF MISSING= 9999999 OR MISSING = 999999.9 OR
       MISSING=99999.9 THEN MISSING=.;
    END;
RUN;
PROC PRINT DATA=COUNTRY;
RUN;

Example 4

LIBNAME PROJECT1 'A:\MYDATA';
DATA; 
  SET PROJECT1.COUNTRY;
PROC PRINT;
RUN;

Example 4

data geol;
   infile "c:\temp\geol.dat";
   input state $ 1-3 county $ 5-12 sqmile 14-19
         region 22-24 tract 27-29 code $ 32-33
         rainfall 37-40 temp 43-46 temptype $ 49;
         if temptype="F" then tempc=(temp-32)/9*5;
         else if temptype="C" then tempc=temp;
proc print data=geol;
run;

MAIN

Last updated: 01/17/07 by Karl Ho.