Entering and Listing Data

 

This is an example of

  1. How to create a SAS data set using INPUT statement
  2. How to create new variables
  3. How to print the SAS data set using PROC PRINT.

 

 

*--- SAS program: ENTRRING_LISTING_DATA.SAS ;

 

data score;

  input name $ gender $ test1 test2 test3;

  average = (test1+test2+test3)/3 ;

  datalines;

Adam      F 93 91 80

Jokh      M 64 53 78

Amy       M 98 84 75

Aliya     M 76 87 74

Cris      F 95 88 83

Josh      M 67 69 62

Tom       F 98 82 96

Gary      F 92 84 87

Mike      M 81 85 88

Matt      M 77 71 79

Mary      F 70 86 70

Patt      M 85 87 95

Magarita  M 78 78 74

Mathew    M 66 69 66

White     F 56 54 67

Gret      M 97 75 78

Sam       F 67 62 63

Kate      F 95 87 81

Uladimir  M 73 78 70

Frank     M 81 89 88

Colyn     F 80 81 94

Bob       F 73 72 77

Rissa     M 87 80 83

Edward    M 94 99 98

;

run;

 

proc print data=grade;

  title "Student Test Score";

run;

 

 

Note:

 

  • DATA statement signals a beginning of DATA step execution.
  • The INPUT statement reads raw data from in-stream data lines or external files into a SAS data set.
  • The statement average = (test1+test2+test3)/3 create a new variable average that by calculating the average of test1, test2  and test3.
  • DATALINES or CARDS statement signals SAS that input data values are to follow.
  • PROC PRINT procedure will produce a listing of the entire data set.

 

 

Ouput from the program is shown below:

 

 

 

                         Student Test Score

 

  Obs    name        gender    test1    test2    test3    average

 

    1    Adam          F         93       91       80     88.0000

    2    Jokh          M         64       53       78     65.0000

    3    Amy           M         98       84       75     85.6667

    4    Aliya         M         76       87       74     79.0000

    5    Cris          F         95       88       83     88.6667

    6    Josh          M         67       69       62     66.0000

    7    Tom           F         98       82       96     92.0000

    8    Gary          F         92       84       87     87.6667

    9    Mike          M         81       85       88     84.6667

   10    Matt          M         77       71       79     75.6667

   11    Mary          F         70       86       70     75.3333

   12    Patt          M         85       87       95     89.0000

   13    Magarita      M         78       78       74     76.6667

   14    Mathew        M         66       69       66     67.0000

   15    White         F         56       54       67     59.0000

   16    Gret          M         97       75       78     83.3333

   17    Sam           F         67       62       63     64.0000

   18    Kate          F         95       87       81     87.6667

   19    Uladimir      M         73       78       70     73.6667

   20    Frank         M         81       89       88     86.0000

   21    Colyn         F         80       81       94     85.0000

   22    Bob           F         73       72       77     74.0000

   23    Rissa         M         87       80       83     83.3333

   24    Edward        M         94       99       98     97.0000