A More Comprehensive Example

Often, a single SAS program contains a large number of data-manipulation and subsetting statements. Consider the following example which makes use of the INFILE statement rather than the DATALINES statement:

 1   DATA D1;
 2      INFILE 'A:/VOLUNTEER.DAT' ;
 3      INPUT   #1   @1    Q1-Q7        1.
 4                   @9    AGE          2.
 5                   @12   IQ           3.
 6                   @16   NUMBER       2.
 7                   @19   SEX         $1.
 8              #2   @1    GREVERBAL    3.
 9                   @5    GREMATH      3.  ;
10
11      DATA D2;
12         SET D1;
13
14      Q3 = 6 - Q3;
15      Q6 = 6 - Q6;
16      RESPONSE = (Q1 + Q2 + Q3) / 3;
17      TRUST    = (Q4 + Q5 + Q6) / 3;
18      SHOULD   =  Q7;
19
20      PROC MEANS   DATA=D2;
21      RUN;
22
23      DATA D3;
24         SET D2;
25         IF SEX = 'F';
26
27      PROC MEANS   DATA=D3;
28      RUN;
29
30      DATA D4;
31         SET D2;
32         IF SEX = 'M';
33
34      PROC MEANS   DATA=D4;
35      RUN;

In the preceding program, ...

Get A Step-by-Step Approach to Using SAS® for Univariate & Multivariate Statistics, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.