Problem Data and Programs

advertisement
***Data and programs for end-of-chapter problems
Cut and paste the lines of data and programs and
copy to you your SAS session;
***Chapter 1:
Problem 1.1
1 18 M 3.7
2 18 F 2.0
3 19 F 3.3
4 23 M 2.8
5 21 M 3.5
650
490
580
530
640
Problem 1.2
00768155150
00272250240
00563240200
00170345298
Problem 1.3
123874414
646239182
012437652
018451357
28,000
29,500
35,100
26,500
35
37
40
31
W
B
W
W
Problem 1.4
***Program to read in IQ and other test scores;
DATA IQ_AND_TEST_SCORES;
INPUT ID
1-3
IQ
4-6
MATH
7-9
SCIENCE 10-12;
DATALINES;
001128550590
002102490501
003140670690
004115510510
;
Problem 1.6
ABCDE
AACCE
BBBBB
CABDA
DDAAC
CABBB
EEBBB
ACACA
Problem 1.8
137 28000 1
214 98000
3
199 150000 3
355
57000
2
Problem 1.9
001
W 130
002
B 140
003
W 120
004
W 150
005
B 124
80
90
70
90
86
60
70
64
76
72
Problem 1.10
Trenton 23 25 30
Newark
18 27 22
Albany
22 21 27
***Chapter 2;
Problem 2.2
001MW08013008010
002FW08811007205
003MB05018810002
004FB
10806801
005MW06812208204
006FB101
07404
007FW07810406603
008MW04811207006
009FB07719011009
010FB06616410610
Problem 2.5
DATA PROB2_5;
LENGTH GROUP $ 1;
INPUT X Y Z GROUP $;
DATALINES;
2
4
6
A
3
3
3
B
1
3
7
A
7
5
3
B
1
1
5
B
2
2
4
A
5
5
6
A
;
Problem 2.7
1 1
5.4
2 1
5.9
3 1
4.8
4 1
6.9
5 1
15.8
6 2
4.9
7 2
5.0
8 2
6.7
9 2
18.2
10 2
5.5
Problem 2.11
10.2
9.8
12.2
11.8
10.9
13.8
12.0
10.5
11.9
9.9
8.9
7.3
9.1
8.8
9.0
6.6
7.9
8.0
6.9
9.1
Brown American 3
Johnson VRW
6
Rivera
Texam 2
Brown Standard 0
Brown Knowles 2
Rivera
Metro 4
Rivera
Uniman
Johnson Oldham
Johnson Rondo 2
12
14
6
22
19
8
8
3
14
28000
33000
8000
0
12000
13000
7 27000
16 8000
2000
Problem 2.13
1 A 44
1 B 9
1 C 203
2 A 50
2 B 7
2 C 188
3 A 39
3 B 9
3 C 234
***Chapter 3;
Problem 3.2
001 1
L B 15
002 2 M
Z
35
003
2 H F 76
004 1 L C 21
005 2 H . 58
Problem 3.3
007M1110
013F2101
137F1001
117 1111
428M3110
017F3101
037M2101
Problem 3.4
*Program to create data set BLOOD;
DATA BLOOD;
DO I = 1 TO 500;
WBC = INT(RANNOR(1368)*2000 + 5000);
X = RANUNI(0);
IF X LT .05 THEN WBC = .;
ELSE IF X LT .1 THEN WBC = WBC - 3000;
ELSE IF X LT .15 THEN WBC = WBC + 4000;
OUTPUT;
END;
DROP I X;
RUN;
Problem 3.5
DATA DEMOG;
INPUT WEIGHT HEIGHT GENDER $;
DATALINES;
155 68 M
98 60 F
202 72 M
280 75 M
130 63 F
.
57 F
166 . M
;
Problem 3.12
***Program to create data set CASE_CONTROL;
LIBNAME PERM 'C:\MYDATA';
***Substitute a libname of your choice, or make the data set
temporary;
DATA PERM.CASE_CONTROL;
ARRAY COUNTS[4] _TEMPORARY_ (50 100 150 35);
DO EXPOSURE = '1-Yes','2-No';
DO OUTCOME = '1-Dead ','2-Alive';
I + 1;
DO N = 1 TO COUNTS[I];
SUBJ + 1;
OUTPUT;
END;
END;
END;
DROP I;
RUN;
Problem 3.14
PROC FORMAT;
VALUE PAIN 1 = 'YES' 2 = 'NO';
VALUE DOSE 1='LOW' 2='MEDIUM' 3='HIGH';
RUN;
DATA DOSE;
DO DOSE = 1 TO 3;
DO I = 1 TO 50;
PAIN = 2 - (RANUNI(135) GT (.6 + .08*DOSE));
OUTPUT;
END;
END;
FORMAT PAIN PAIN. DOSE DOSE.;
RUN;
Problem 3.19
11127 78130 80
1787 82180110
031
62120 78
4261 68130 80
89
58120 76
9948 82178100
Problem 3.20
***Program to create the data set CLASSICAL;
PROC FORMAT;
VALUE COMPOSER 1 = 'Bach'
2 = 'Handel'
3 = 'Scarlatti'
4 = 'Hayden'
5 = 'Mozart'
6 = 'Beethoven'
7 = 'Schubert'
8 = 'Brahms'
9 = 'Schumann'
10 = 'Stravinsky'
11 = 'Shostakovich';
RUN;
DATA CLASSICAL;
INPUT SUBJ $ GENDER : $1. CHOICE1 CHOICE2 CHOICE3;
DATALINES;
1 M 6 4 5
2 F 2 4 3
3 M 7 11 9
4 M 5 6 3
5 F 7 8 10
6 F 1 2 4
7 M 6 5 9
8 M 2 9 11
9 F 5 1 2
;
***Chapter 4;
Problem 4.1
001 1021194611121980122819887343
002 0913195502021980020419880123
005 0606194003121981031220040000
003 0705194411151980111320009544
Problem 4.2
***Program to create data set ABC_CORP;
DATA ABC_CORP;
DO SUBJ = 1 TO 10;
DOB = INT(RANUNI(1234)*15000);
VISIT_DATE = INT(RANUNI(0)*1000) + '01JAN2000'D;
OUTPUT;
END;
FORMAT DOB VISIT_DATE DATE9.;
RUN;
Problem 4.3
1 23MAY1990
2 21MAY1990
3 23MAY1990
4 27MAY1990
5 22MAY1990
23JUN1990
27JUN1990
25JUN1990
07JUL1990
29JUN1990
28JUN1990
05JUL1990
01JUL1990
15JUL1990
22JUL1990
A
A
A
A
B
6
7
8
26MAY1990
24MAY1990
29MAY1990
03JUL1990
01JUL1990
15JUL1990
03AUG1990
29JUL1990
18AUG1990
B
B
B
Problem 4.4
DATA CLINICAL;
*Use LENGTH statement to control the order of
variables in the data set;
LENGTH PATIENT VISIT DATE_VISIT 8;
RETAIN DATE_VISIT WEIGHT;
DO PATIENT = 1 TO 25;
IF RANUNI(135) LT .5 THEN GENDER = 'Female';
ELSE GENDER = 'Male';
X = RANUNI(135);
IF X LT .33 THEN GROUP = 'A';
ELSE IF X LT .66 THEN GROUP = 'B';
ELSE GROUP = 'C';
DO VISIT = 1 TO INT(RANUNI(135)*5);
IF VISIT = 1 THEN DO;
DATE_VISIT = INT(RANUNI(135)*100) + 15800;
WEIGHT = INT(RANNOR(135)*10 + 150);
END;
ELSE DO;
DATE_VISIT = DATE_VISIT + VISIT*(10 + INT(RANUNI(135)*50));
WEIGHT = WEIGHT + INT(RANNOR(135)*10);
END;
OUTPUT;
IF RANUNI(135) LT .2 THEN LEAVE;
END;
END;
DROP X;
FORMAT DATE_VISIT DATE9.;
RUN;
Problem 4.9
***Program to create data set BLOOD;
DATA BLOOD;
LENGTH GROUP $ 1;
INPUT ID GROUP $ TIME WBC RBC @@;
DATALINES;
1 A 1 8000 4.5 1 A 2 8200 4.8 1 A 3 8400 5.2
1 A 4 8300 5.3 1 A 5 8400 5.5
2 A 1 7800 4.9 2 A 2 7900 5.0
3 B 1 8200 5.4 3 B 2 8300 5.4 3 B 3 8300 5.2
3 B 4 8200 4.9 3 B 5 8300 5.0
4 B 1 8600 5.5
5 A 1 7900 5.2 5 A 2 8000 5.2 5 A 3 8200 5.4
5 A 4 8400 5.5
;
***Chapter 5;
Problem 5.1
1 3 15
7
8
3
4
13
12
4
7
7
5
14
10
Problem 5.2
DATA EXAM;
INPUT (Q1-Q8)(1.);
DATALINES;
10101010
11111111
11110101
01100000
11110001
11111111
11111101
11111101
10110101
00010110
;
Problem 5.3
15 116
20 120
25 130
30 132
40 150
50 148
Problem 5.4
DATA SCORES;
DO SUBJECT = 1 TO 100;
IF RANUNI(1357) LT .5 THEN GROUP = 'A';
ELSE GROUP = 'B';
MATH = ROUND(RANNOR(1357)*20 + 550 + 10*(GROUP EQ 'A'));
SCIENCE = ROUND(RANNOR(1357)*15 + .4*MATH + 300);
ENGLISH = ROUND(RANNOR(1357)*20 + 500 + .05*SCIENCE +
.05*MATH);
SPELLING = ROUND(RANNOR(1357)*15 + 500 + .1*ENGLISH);
VOCAB = ROUND(RANNOR(1357)*5 + 400 + .1*SPELLING +
.2*ENGLISH);
PHYSICAL = ROUND(RANNOR(1357)*20 + 550);
OVERALL = ROUND(MEAN(MATH, SCIENCE, ENGLISH, SPELLING, VOCAB,
PHYSICAL));
OUTPUT;
END;
RUN;
Problem 5.8
4 180
110
4 190
108
4 178
100
8 170
100
8 180
98
8
16
16
16
32
32
32
168
160
172
170
140
130
128
88
80
86
86
80
72
70
Problem 5.11
1 35 1 2 YES
2 88 5 8 NO
3 5 0 1 YES
4 55 3 3 YES
5 75 4 5 NO
6 125
5 8 NO
7 225
7 9 YES
8 500
10 11 NO
***Chapter 6;
Problem 6.1
40 35
42 37
48 42
35 22
62 38
35 29
Problem 6.2
***Note: Data arranged for easy input;
Cody 500
Cody 450
Cody 505
Cody 404
Cody 555
Cody 567
Cody 588
Cody 577
Cody 566
Cody 644
Cody 511
Cody 522
Cody 543
Cody 578
Smith 355
Smith 388
Smith 440
Smith 600
Smith 510
Smith 501
Smith 502
Smith 489
Smith 499
Smith 489
Smith
Smith
Smith
Smith
515
520
520
480
Problem 6.4
DATA QUES6_4;
DO GROUP = 'A','B','C';
DO I = 1 TO 10;
X = ROUND(RANNOR(135)*10 + 300 +
5*(GROUP EQ 'A') - 7*(GROUP EQ 'C'));
Y = ROUND(RANUNI(135)*100 + X);
OUTPUT;
END;
END;
DROP I;
RUN;
Problem 6.5
1 20 18
2 40 36
3 30 30
4 45 46
5 19 15
6 27 22
7 32 29
8 26 25
Problem 6.6
***Note: data arranged for easy input;
1 300 290
2 350 351
3 190 200
4 400 395
5 244 240
6 321 300
7 330 332
8 250 242
9 190 185
10 160 158
11 260 256
12 240 220
***Chapter 7;
Problem 7.1
8 4 12
10 7 8
9 5 10
11 5 10
10 6 11
10 7 9
8 6 9
12 4 12
Problem 7.2
220 190 180
160 168 178
240 220 246
185
200
244
210
172
198
170
155
238
178
159
277
200
167
255
Problem 7.3
***Note: Data arranges for easy INPUT;
NEW W 67
NEW W 72
NEW W 74
NEW W 82
NEW W 81
NEW P 75
NEW P 76
NEW P 80
NEW P 72
NEW P 73
OLD W 46
OLD W 44
OLD W 45
OLD W 51
OLD W 43
OLD P 63
OLD P 62
OLD P 66
OLD P 62
OLD P 60
Problem 7.4
***Note: Data arranged for easy INPUT;
A 560
A 520
A 530
A 525
A 575
A 527
A 580
A 620
B 565
B 522
B 520
B 530
B 510
B 522
B 600
B 590
C 512
C 518
C 555
C 502
C 510
C 520
C 516
177
185
190
189
199
188
D
D
D
D
D
D
D
505
508
512
520
543
523
517
Problem 7.5
***Note: Order is
C 1 7 C 1 6 C 1
P 1 9 P 1 9 P 1
C 2 9 C 2 7 C 2
P 2 6 P 2 5
BRAND AGE
6 C 1 5
9 P 1 8
8 C 2 8
TASTE;
C 1 6 P 1 9
C 2 9 C 2 8
P 2 6 P 2 7
P 1 8
C 2 8
P 2 6
Problem 7.6
Note: Order is GROUP DRUG DEPRESSION;
DEFICIENT DRUG 9
DEFICIENT PLACEBO 9
DEFICIENT DRUG 11
DEFICIENT PLACEBO 6
DEFICIENT DRUG 10
DEFICIENT PLACEBO 6
DEFICIENT DRUG 10
DEFICIENT PLACEBO 7
NORMAL DRUG 5
NORMAL PLACEBO 12
NORMAL DRUG 4
NORMAL PLACEBO 11
NORMAL DRUG 7
NORMAL PLACEBO 10
NORMAL DRUG 7
NORMAL PLACEBO 11
Problem 7.8
DATA CO_VARY;
DO I = 1 TO 20;
DO GROUP = 'A','B';
SUBJ + 1;
IQ = INT(RANNOR(124)*10 + 120 + 15*(GROUP EQ 'A'));
SCORE = INT(.7*IQ + RANNOR(0)*10 + 100 + 10*(GROUP EQ 'B'));
OUTPUT;
END;
END;
DROP I;
RUN;
Problem
3 Mo. A
3 Mo. A
3 Mo. A
3 Mo. A
3 Mo. A
3 Mo. A
7.10
12
14
9
17
10
11
3
3
3
3
3
3
3
6
6
6
6
6
6
6
6
6
6
6
9
9
9
9
9
9
9
9
9
9
9
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
Mo.
A
A
B
B
B
B
B
A
A
A
A
A
A
A
B
B
B
B
A
A
A
A
A
A
A
B
B
B
B
9
10
24
17
22
16
18
22
20
12
12
17
14
17
23
26
34
20
14
14
10
15
17
12
19
27
29
27
23
Problem 7.11
***Note: Order is GROUP M_SCORE AGE;
A 90 16
B 92 18
C 97 18
A 88 15
B 88 13
C 92 17
A 72 12
B 76 12
C 88 16
A 82 14
B 78 14
C 92 17
A 65 12
B 90 17
C 99 17
A 74 13
B 68 12
C 82 14
***Chapter 8;
Problem 8.1
11836
21747
31767
41846
12635
22534
32546
42436
13988
23877
33978
43887
Problem 8.2
DATA STATIN;
DO SUBJ = 1 TO 20;
IF RANUNI(1557) LT .5 THEN GENDER = 'FEMALE';
ELSE GENDER = 'MALE';
IF RANUNI(0) LT .3 THEN DIET = 'HIGH FAT';
ELSE DIET = 'LOW FAT';
DO DRUG = 'A','B','C';
LDL = ROUND(RANNOR(1557)*20 + 110
+ 5*(DRUG EQ 'A')
- 10*(DRUG EQ 'B')
- 5*(GENDER EQ 'FEMALE')
+ 10*(DIET EQ 'HIGH FAT'));
HDL = ROUND(RANNOR(1557)*10 + 20
+ .2*LDL
+ 12*(DRUG EQ 'B'));
TOTAL = ROUND(RANNOR(1557)*20 + LDL + HDL + 50
-10*(GENDER EQ 'FEMALE')
+10*(DIET EQ 'HIGH FAT'));
OUTPUT;
END;
END;
RUN;
Problem 8.3
00118
00126
00138
00145
00215
00226
00235
00244
00317
00324
00336
00344
00417
00425
00437
00443
Problem 8.5
0018685
0025654
0037464
0047573
Problem 8.7
N 1 34 38
N 2 28 38
N 3 38 48
N 4 32 38
D 5 44 42
D 6 52 48
D 7 46 46
D 8 54 50
***Chapter 9;
Problem 9.1
12 1 1 20 2
9 1 1 16 2
8 1 1 16 2
13 1 2 18 3
15 1 2 25 3
14 1 2 20 3
16 2 1 25 3
14 2 1 27 3
12 2 1 29 3
2
2
2
1
1
1
2
2
2
Problem 9.3
4 5 3 20
5 8 3 40
10 40 3 100
1 4 2 50
.5 2 1 300
2 8 1 400
7 30 3 40
4 20 2 200
1 10 2 5
1 12 1 100
Problem 9.5
3.9
3.8
3.9
3.9
3.8
3.8
3.1
3.5
2.9
2.7
2.7
2.5
2.2
2.5
2.1
1.9
1.9
2.2
1.4
2.4
680
720
650
620
480
440
500
380
380
400
130
110
120
125
110
100
115
105
110
110
Problem 9.6
DATA EXERCISE;
DO SUBJ = 1 TO 500;
IF RANUNI(155) LT .5 THEN GENDER = 'Female';
ELSE GENDER = 'Male';
PRESS = INT(RANNOR(0)*20 + 95 + 50*(GENDER EQ 'Male'));
CURL = RANNOR(0)*10 + 30 + .2*PRESS;
PUSHUPS = INT(RANNOR(0)*3 + 5 + 5*(GENDER EQ 'Male')
+ .1*CURL);
SITUPS = INT(RANNOR(0)*10 + 20 + .1*PRESS + PUSHUPS);
OUTPUT;
END;
RUN;
Problem 9.8
PROC FORMAT;
VALUE YESNO 1='YES' 0='NO';
VALUE OUTCOME 1='Case' 0='Control';
RUN;
DATA SMOKING;
DO SUBJECT = 1 TO 1000;
DO OUTCOME = 0,1;
IF RANUNI(567) LT .1 OR RANUNI(0)*OUTCOME GT .5 THEN
SMOKING = 1;
ELSE SMOKING = 0;
IF RANUNI(0) LT .05 OR
(RANUNI(0)*OUTCOME + .1*SMOKING) GT .6 THEN ASBESTOS = 1;
ELSE ASBESTOS = 0;
IF RANUNI(0) LT .3 OR OUTCOME*RANUNI(0) GT .9 THEN
SES = '1-Low
';
ELSE IF RANUNI(0) LT .3 OR OUTCOME*RANUNI(0) GT .8 THEN
SES = '2-Medium';
ELSE SES = '3-High';
OUTPUT;
END;
END;
FORMAT SMOKING ASBESTOS YESNO. OUTCOME OUTCOME.;
RUN;
Problem 9.13
1 0 1
1 1 1
1 1 1
1 0 0
1 1 1
0 0 1
0 1 0
0 1 0
0 0 1
0 0 0
0 1 0
0 0 1
0 1 0
0 0 0
0
1
1
1
1
1
1
1
1
1
1
0
0
1
0
1
1
0
1
1
0
1
1
1
0
0
1
1
1
1
1
0
1
0
1
1
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
0
0
1
0
0
1
0
0
1
1
1
1
1
1
1
1
1
1
0
0
1
0
0
0
1
0
1
0
1
1
1
***Chapter 10;
Problem 10.2
DATA PRINCIPAL;
DO SUBJ = 1 TO 200;
X1 = ROUND(RANNOR(123)*50
X2 = ROUND(RANNOR(123)*50
X3 = ROUND(RANNOR(123)*50
X4 = ROUND(RANNOR(123)*50
OUTPUT;
END;
RUN;
***Chapter 11;
Proglem 11.1
123-45-6789 B
001-44-5559 A
012-12-1234 B
135-63-2837 C
005-00-9999 E
789-78-7878 B
Problem 11.2
C
B
C
B
C
C
D
C
C
D
E
D
A
D
A
A
C
A
A
E
B
A
E
A
+
+
+
+
500);
100 + .8*X1);
100 + X1 - .5*X2);
.3*X1 + .3*X2 + .3*X3);
001
002
003
004
005
006
007
008
009
010
ABCDBECDBE
ABCDEABCDE
ABCDEABCDD
ABCEDABCCE
BBCDEBBCDE
CABEDACBED
DECAACEDAA
ABCDEBBBEE
DDDDDABCDE
ABECDABCDE
Problem 11.4
S S N N S S
S S N N N N
N N
S S
S N
N S
S S
S S
N S
N N
N N
S S
Problem 11.5
C C
X X
X X
C X
X C
X X
X X
C X
C C
C C
X X
C C
C C
X X
***Chapter 12;
Problem 12.1
***Part A;
P
77
P
76
P
74
P
72
P
78
D
80
D
84
D
88
D
87
D
90
***Part B;
P 77 P 76 P 74 P 72 P 78
D 80 D 84 D 88 D 87 D 90
***Part C;
77 76 74 72 78
80 84 88 87 90
Problem 12.2
10/21/1950,03MAY2004,M,Schneider
11/12/1944,05DEC2004,F,Strawderman
01/01/1960,25APR2004,M,Smith
Problem 12.3
1,3,5,7
2,4,6,8
9,8,7,6
Problem 12.4
N N
S S
S N
Bradley,35,68,155
"Bill Johnson",,70,200
"Smith,Jeff",27,70,188
Problem 12.5
1,,"HELLO",7
2,4,TEXT,8
9,,,6
21,31,SHORT
100,200,"LAST LINE",999
Problem 12.6
Cody
M05/11/1981
McMaster
F11/11/1967
Bill Smith M12/25/1999
Problem 12.7
1 10/01/1996
V075
$102.45
2
02/05/1997
X123456789 $3,123
3
07/07/1996
V4568
4
11/11/1996
A123
$777.
Problem 12.8
***Header line: ID GENDER DOB SCORE1 SCORE2
001 M 10/10/1976 100 99
002 F 01/01/1960 89
003 M 05/07/2001 90 98
Problem 12.9
A12 X 111213
A13 W 102030
Problem 12.10
DATA PAIRS;
INPUT @1 GROUP1 $1.
@2 SCORE1 3.
@6 GROUP2 $1.
@7 SCORE2 3.
@11 GROUP3 $1.
@12 SCORE3 3.;
DATALINES;
A100 B 90 C 76
C 87 A 86 B 88
C 93 B 92 A 90
;
Problem 12.12
5 90 80 70 77 88 23
2 100 99 25
3 87 85 88 35
Problem 12.13
123M
102146111196111396
456F
010150122596020597
130 8668134 8872136 8870
220110822101028424012084
Problem 12.14
123121234217874444123872345873235432
192837465748392919283747372818182838
Problem 12.15
01 2345
AAAX
02 9876
BBBY
Problem 12.16
001,M,06/14/1944
68,155
002,F,12/25/1967
52,99
003,M,07/04/1983
72,128
Problem 12.17
1 2 3 4 5 6 7 8
11 12 13 14
21 22 23 24 25 26
27 28
Problem 12.18
04/04/2004M15 90
05/12/2004F16 95
07/23/2004M18 88
01/20/2004F17100
Problem 12.19
00168155
1
00272201
1
0034570170 2
0045562 90 2
***Chapter 13;
Problem
001 56
002 44
003 64
13.1
64 130 80
72 180
78 140 88
Problem 13.2
1,2,3
4,9999,5
9999,6,7
1,2
6,4,3
Problem 13.4
(Copy appropriate lines to data files)
File FILE1.CSV
"001",1,2,3
"002",,4,5
"003",6,7
File FILE2.CSV
"004",10,20,30
"005",40,50,60
File FILE3.CSV
"006",100,200,300
"007",400,,800
Problem 13.6
DATA BIG;
DO I = 1 TO 100000;
X = RANUNI(0);
OUTPUT;
END;
DROP I;
RUN;
DATA SMALL;
X = .5;
OUTPUT;
X = .6;
OUTPUT;
RUN;
Problem
***2004
M 1 0 1
F 0 0 1
M 1 1 1
F 0 0 0
13.8
Survey***
0 1
1 0
1 1
1 0
Problem 13.9
***DATA step to create MILTON;
DATA MILTON;
INPUT X Y A B C Z;
DATALINES;
1 2 3 4 5 6
11 22 33 44 55 66
;
***Chapter 14;
Problem 14.1
3
M
8
5
F
14
2
F
10
7
M
9
6
F
15
7.5
7.9
5.6
5.4
8.2
7.2
8.2
5.7
5.9
8.2
Problem 14.3
DATA YEAR1996;
INPUT ID HEIGHT WEIGHT;
6.5
6.8
5.8
6.1
7.9
DATALINES;
2 68 155
1 63 102
4 61 111
;
DATA YEAR1997;
INPUT ID HEIGHT WEIGHT;
DATALINES;
7 72 202
5 78 220
3 66 105
;
Problem 14.4
DATA ONE TWO THREE;
DO I = 1 TO 5;
DO TIME = 1 TO 3;
DOB = INT(10000 + RANUNI(0)*365);
WEIGHT = RANNOR(0)*50 + 150;
IF TIME = 1 THEN OUTPUT ONE;
ELSE IF TIME = 2 THEN OUTPUT TWO;
ELSE IF TIME = 3 THEN OUTPUT THREE;
END;
END;
DROP I;
FORMAT DOB DATE9.;
RUN;
Problem 14.5
3
A
Klein
7
B
Cesar
8
A
Solanchick
1
B
Warlock
5
A
Cassidy
2
B
Volick
Problem 14.6
DATA TEMP;
IF _N_ = 1 THEN DATE = '01JAN2004'D;
ELSE DATE + 1;
FORMAT DATE MMDDYY10.;
INPUT T @@;
DATALINES;
30 32 28 26 25 12 18 20 22 24 36 38 38 39 44
;
DATA MI;
IF _N_ = 1 THEN DATE = '01JAN2004'D;
ELSE DATE + 1;
FORMAT DATE MMDDYY10.;
INPUT NUMBER @@;
DATALINES;
9 7 11 12 15 23 20 18 8 9 13 12 14 13 14
;
Problem 14.8
DATA STUDENT;
INPUT ID NAME & $30. @@;
DATALINES;
1 John Torres 5 Alex Antoniou 3 Thomas Friend
2 Sheldon Goldstein 11 Joanne Dipietro 12 Bill Murray
21 Janet Reno 4 Deborah Smith 6 Don Dubin 7 Alice Ford
8 Diane Farley 9 Laura Easton 10 Brian Fishmann
13 Eric Garrett 14 James Galt 15 Toni Gilman
;
DATA TEST;
INPUT ID SCORE @@;
DATALINES;
15 95 1 80 3 98 21 75 4 87 14 67 13 91 11 85 12 57
29 93
;
Problem 14.9
A
M
W
A
F
X
B
M
Y
B
F
Z
Problem 14.10
DATA PRICES;
INPUT PART_NUMBER QUANTITY PRICE @@;
DATALINES;
100 23 29.95 102 12 9.95 103 21 15.99
111 55 39.95 105 500 .59
;
***Chapter 15;
Problem 15.1
DATA PROB15_1;
INPUT (HT1-HT5)(2.) (WT1-WT5)(3.);
DENS1 = WT1 / HT1**2;
DENS2 = WT2 / HT2**2;
DENS3 = WT3 / HT3**2;
DENS4 = WT4 / HT4**2;
DENS5 = WT5 / HT5**2;
DATALINES;
6862727074150090208230240
64 68 70140
150
170
;
Problem 15.2
DATA TEMPERATURE;
INPUT TF1-TF10;
TC1 = 5/9*(TF1 TC2 = 5/9*(TF2 TC3 = 5/9*(TF3 TC4 = 5/9*(TF4 TC5 = 5/9*(TF5 -
32);
32);
32);
32);
32);
123 9 119.95
113 40 56.66
TC6 = 5/9*(TF6 - 32);
TC7 = 5/9*(TF7 - 32);
TC8 = 5/9*(TF8 - 32);
TC9 = 5/9*(TF9 - 32);
TC10 = 5/9*(TF10 - 32);
DATALINES;
32 212 -40 10 20 30 40 50 60 70
-10 0 10 20 30 40 50 60 70 80
;
PROC PRINT DATA=TEMPERATURE NOOBS;
TITLE "Listing of Data Set TEMPERATURE";
RUN;
Problem 15.3
DATA OLDMISS;
INPUT A B C X1-X3 Y1-Y3;
IF A = 999 THEN A = .;
IF B = 999 THEN B = .;
IF C = 999 THEN C = .;
IF X1 = 999 THEN X1 = .;
IF X2 = 999 THEN X2 = .;
IF X3 = 999 THEN X3 = .;
IF Y1 = 777 THEN Y1 = .;
IF Y2 = 777 THEN Y2 = .;
IF Y3 = 777 THEN Y3 = .;
DATALINES;
1 2 3 4 5 6 7 8 9
999 4 999 999 5 999 777 7 7
;
Problem 15.4
DATA MIXED;
INFORMAT A1-A3 B C $5.;
INPUT X1-X3 Y Z A1-A3 B C;
LX1 = LOG(X1);
LX2 = LOG(X2);
LX3 = LOG(X3);
LY = LOG(Y);
LZ = LOG(Z);
IF A1 = '?' THEN A1 = ' ';
IF A2 = '?' THEN A2 = ' ';
IF A3 = '?' THEN A3 = ' ';
IF B = '?' THEN B = ' ';
IF C = '?' THEN C = ' ';
DATALINES;
10 20 30 40 50 ONE TWO THREE ? ?
11 22 33 44 55 ? LLL MMM ? VVV
;
PROC PRINT DATA=MIXED NOOBS;
TITLE "Listing of Data Set MIXED";
RUN;
Problem 15.5
***Program to create the data set SPEED;
DATA SPEED;
INPUT X1-X5 Y1-Y3;
DATALINES;
1 2 3 4 5 6 7 8
11 22 33 44 55 66 77 88
;
Problem 15.6
DATA ANSWERS;
***Passing grades: 65, 70, 60, 75, and 66;
INPUT ID $ SCORE1-SCORE5;
DATALINES;
001 50 70 62 78 85
002 90 86 87 91 94
003 63 72 58 73 68
;
Problem 15.7
DATA PROB15_7;
LENGTH C1-C5 $ 2;
INPUT C1-C5 $ X1-X5 Y1-Y5;
IF C1 = 'NA' THEN C1 = ' ';
IF C2 = 'NA' THEN C2 = ' ';
IF C3 = 'NA' THEN C3 = ' ';
IF C4 = 'NA' THEN C4 = ' ';
IF C5 = 'NA' THEN C5 = ' ';
IF X1 = 999 OR Y1 = 999 THEN DO;
X1 = .;
Y1 = .;
END;
IF X2 = 999 OR Y2 = 999 THEN DO;
X2 = .;
Y2 = .;
END;
IF X3 = 999 OR Y3 = 999 THEN DO;
X3 = .;
Y3 = .;
END;
IF X4 = 999 OR Y4 = 999 THEN DO;
X4 = .;
Y4 = .;
END;
IF X5 = 999 OR Y5 = 999 THEN DO;
X5 = .;
Y5 = .;
END;
DATALINES;
AA BB CC DD EE 1 2 3 4 5 6 7 8 9 10
NA XX NA YY NA 999 2 3 4 999 999 4 5 6 7
;
Problem 15.8
DATA EXPER;
INPUT TIME0-TIME4;
DATALINES;
100 200 300 400 500
55 110 130 150 170
;
***Chapter 16;
Problem 16.1
DATA FROG;
INPUT ID X1-X5 Y1-Y5;
DATALINES;
01
4
5
4
7
3
1
02
8
7
8
6
7
5
;
7
4
3
3
6
5
Problem 16.2
DATA QUES;
INPUT ID $ REASON1-REASON4;
DATALINES;
001 3 6 13 17
002 8 3 4 .
003 20 2 . .
004 8 4 20 19
;
Problem 16.3
DATA STATE;
INFORMAT STATE1-STATE5 $ 2;
INPUT ID STATE1-STATE5;
DATALINES;
1
NY
NJ
PA
TX
GA
2
NJ
NY
CA
XX
XX
3
PA
XX
XX
XX
XX
;
Problem 16.4
DATA THIN;
INPUT ID $
DATALINES;
001 1 10 001
004 1 17
003 1 14 003
002 1 18 004
;
TIME X @@;
2 12
001 3 15
2 18
2 28
003 3 22
003 4 28
Problem 16.6
DATA OLDFASH;
SET BLAH;
ARRAY JUNK(J) X1-X5 Y1-Y5 Z1-Z5;
DO OVER JUNK;
IF JUNK = 999 THEN JUNK=.;
END;
DROP J;
RUN;
8
6
***Chapter 17;
Problem 17.1
DATA HOSP;
INFORMAT ID $3. GENDER $1. DOB DOS MMDDYY8.;
INPUT ID GENDER DOB DOS LOS SBP DBP HP;
FORMAT DOB DOS MMDDYY10.;
DATALINES;
1 M 10/21/46 3/17/97 3 130 90 68
2 F 11/1/55 3/1/97 5 120 70 72
3 M 6/6/90 1/1/97 100 102 64 88
4 F 12/21/20 2/12/97 10 180 110 86
;
Problem 17.2
DATA FUNCTIONS;
INPUT @1 SUBJECT
$3.
@4 DOB
MMDDYY10.
@14 VISIT
MMDDYY10.
@23 (SCORE1-SCORE6)(2.);
FORMAT DOB VISIT MMDDYY10.;
DATALINES;
00110/21/195011/11/2004908070757688
00205/05/200312/20/200499 98 9790
00307/15/194107/06/2004
9896
00406/24/193709/25/2004777879808182
;
Problem 17.3
DATA MANY;
INPUT X1-X5 Y1-Y5;
DATALINES;
1 2 3 4 5 6 7 8 9 10
3 . 5 . 7 5 . . . 15
9 8 . . . 4 4 4 4 1
;
Problem 17.4
DATA BIG;
DO SUBJ = 1 TO 100;
X = INT(RANUNI(123)*100 + 1);
OUTPUT;
END;
RUN;
Problem 17.9
DATA MIXED;
INPUT X Y A $ B $;
DATALINES;
1 2 3 4
5 6 7 8
;
Problem 17.10
DATA NUM_CHAR;
INPUT X $ Y $ Z $ DATE : $10. NUMERAL DOB : DATE9.;
FORMAT DOB MMDDYY10.;
DATALINES;
10 20 30 10/21/1946 123 09SEP2004
1 2 3 11/11/2004 999 01JAN1960
;
***Chapter 18;
Problem 18.1
DATA CHAR1;
INPUT @1 STRING1 $1.
@2 STRING2 $5.
@3 STRING3 $8.
@11 (C1-C5)($1.);
DATALINES;
XABCDE12345678YNYNY
YBBBBB12V56876yn YY
ZCCKCC123-/. ,WYNYN
;
Problem 18.2
DATA ADDRESS;
INPUT #1 @1 LINE1 $50.
#2 @1 LINE2 $50.
#3 @1 LINE3 $50.;
DATALINES;
Mr. Jason
Simmons
123 Sesame Street
Madison, WI
Dr. Justin Case
78
River Road
Flemington, NJ
Ms.
Marilyn Crow
777 Jewell
Place
;
Problem 18.4
DATA STRING;
INPUT STRING $10.;
DATALINES;
123nj76543
892NY10203
876pA83745
;
Problem 18.6
DATA GOOD_BAD;
INPUT ANSWER $40.;
DATALINES;
1324AcB876acccCCC
123 456
aabbccAABBCC123123
abcde12345
invalid
;
Problem 18.7
DATA PHONE;
INPUT CHAR_NUM $20.;
DATALINES;
(908)235-4490
(800) 555 - 1 2 1 2
203/222-4444
;
Problem 18.8
DATA ONE;
INPUT @1 ID
$11.
@12 NAME $15.;
DATALINES;
123-45-6789Jeff Smith
111-22-3333Stephen King
999-88-7777Jan Chambliss
;
DATA TWO;
INPUT @1 ID 9.
@11 SCORE 3.;
DATALINES;
999887777 100
123456789 65
111223333 59
;
Problem 18.9
DATA EXPER;
INPUT ID
$ 1-5
GROUP $ 7
DOSE
$ 9-12;
DATALINES;
1NY23 A HIGH
3NJ99 B HIGH
2NY89 A LOW
5NJ23 B LOW
;
Problem 18.10
1 50kg 2 120 3 121Lbs.
6 80kG 7 250lb
Problem 18.12 (a)
ABC123XYZ7823
NONE HERE
XYZ12345
12345XYZ9876
4 88KG.
5 200
Problem 18.12 (b)
B4Y7999Z5V8
NONE HERE
ONLY ONE X8
Z8Z9
Problem 18.13
DATA ONE;
INPUT @1 GENDER$1.
@2 DOBMMDDYY8.
@10 NAME$11.
@21 STATUS$1.;
FORMAT DOB MMDDYY8.;
DATALINES;
M10/21/46CADYA
F11/11/50CLINEB
M11/11/52SMITHA
F10/10/80OPPENHEIMERB
M04/04/60JOSEA
;
DATA TWO;
INPUT @1 GENDER$1.
@2 DOBMMDDYY8.
@10 NAME$11.
@21 WEIGHT3.;
FORMAT DOB MMDDYY8.;
DATALINES;
M10/21/46CODY160
F11/11/50CLEIN102
F11/11/52SMITH101
F10/10/80OPPENHAIMER120
M02/07/60JOSA220
;
Problem 18.14
DATA VERSE;
INPUT LONG_STRING $50.;
DATALINES;
The time was early and the sky was still dark
This line does not contain any
Four the last time, the man walked the plank
;
Download