You are on page 1of 23

Midterm

1.1)

code

/* I completed the assignment at home because of restricted library hours and for
convenience.
The second one is the only way I can import raw data into SAS
UniversityEdition*/
libname Final 'C:\Users\strachan\Desktop';
Data Final.temperature;
infile 'C:\Users\strachan\Desktop\temperature.txt';
input temp gender$ rate;
run;
proc report data = Final.temperature;
column gender temp rate;
define gender / order;
title 'This output was produced by Jeffey Strachan';
run;
data HEARTRATE;
set Final.temperature;
proc sort data = Final.temperature;
by gender;
run;
proc print data = HEARTRATE noobs;
by gender;
where rate>=85;
var temp rate;
run;

libname Final '/folders/myfolders';


Data Final.temperature;
infile '/folders/myshortcuts/Myfolders/temperature.txt';
input temp gender$ rate;
run;
proc report data = Final.temperature;
column gender temp rate;
define gender / order;
title 'This output was produced by Jeffey Strachan';
run;
data HEARTRATE;
set Final.temperature;
proc sort data = Final.temperature;
by gender;
run;
proc print data = HEARTRATE noobs;
by gender;
where rate>=85;
var temp rate;
run;
1) log (b)

2)
OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
3) 55
4) 56
proc report data = Final.temperature;
5) 57
column gender temp rate;
6) 58
define gender / order;
7) 59
title 'This output was produced by Jeffey Strachan';
8) 60
run;
9)
10) NOTE: There were 130 observations read from the data set
FINAL.TEMPERATURE.
11) NOTE: PROCEDURE REPORT used (Total process time):

12)
real time
0.15 seconds
13)
cpu time
0.14 seconds
14)
15)
16) 61
17) 62
OPTIONS NONOTES NOSTIMER NOSOURCE
NOSYNTAXCHECK;
18) 74

1) Log (c)

2)
3)
4)
5)
6)
7)

OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;


55
56
data HEARTRATE;
57
set Final.temperature;

NOTE: There were 130 observations read from the data set
FINAL.TEMPERATURE.
8) NOTE: The data set WORK.HEARTRATE has 130 observations and 3
variables.
9) NOTE: DATA statement used (Total process time):
10)
real time
0.01 seconds
11)
cpu time
0.01 seconds
12)
13) 58
proc sort data = Final.temperature;
14)
15) 59
by gender;
16) 60
run;
17)
18) NOTE: Input data set is already sorted, no sorting done.
19) NOTE: PROCEDURE SORT used (Total process time):
20)
real time
0.00 seconds
21)
cpu time
0.00 seconds
22)
23)
24) 61
proc print data = HEARTRATE noobs;
25) 62
by gender;
26) 63
where rate>=85;
27) 64
var temp rate;
28) 65
run;

29)
30) NOTE: There were 6 observations read from the data set
WORK.HEARTRATE.
31)
WHERE rate>=85;
32) NOTE: PROCEDURE PRINT used (Total process time):
33)
real time
0.04 seconds
34)
cpu time
0.04 seconds
35)
36)
37) 66
38) 67
OPTIONS NONOTES NOSTIMER NOSOURCE
NOSYNTAXCHECK;
39) 79

1) Output (B)

1) Output (b)

1.2)

P1Q2) 2. height-in-cm is not valid because other than underscore special characters
are not allowed.
5. 7kg_Tom is not valid because variable name cannot begin with
number.
P1Q3) 1. temperature_data and 2. height_cm are not valid because libref names can
only be 8 or less characters in length.
4. - and 5. 7kg_Tom are not valid libref names because they are not
valid sas names.
P1Q4) 001. data-2 is not a valid sas data set name.
correction: data data_2;
002. file path must be specified in a infile statement and in quotes.

correction: infile 'c:\Users\Jeff\Desktop\p4dt.txt';


003. All statements must end with semicolons.
correction: input x1 x2;
004. * needed to denote multiplication.
correction: y1 = 3*(x1) + (x2)**2;
P1Q5) If we ran the data step after closing the datalines with a semicolon, then
there are five observations and 2 variables.
There is no output. Yes, we need to format variable
accum_parking_revenue and a proc print statement.
P1Q6)
data d1;
input V R E;
cards;
2.5 3.1 2.0
1.2 2.8 3.9
;
run;
data d2;
set d1;
EMF = 1.45*V + (R/E)*(V)**3 -125 ;
proc print data = d2;
var EMF V R E;
run;
2)
libname Final '/folders/myfolders';
data Final.climate;
infile '/folders/myfolders/sasuser.v94/climate.txt';
input SchoolCode Gender q1-q7;
safety = sum(of q1-q4);
close = mean(of q5-q7);

label
SchoolCode = 'SchoolName'
Gender = 'Sex'
q1 = 'Students treat peers with respect.'
q2 = 'Staff treat students with respect.'
q3 = 'Students resolve conflicts peacefully.'
q4 = 'School feels safe and caring.'
q5 = 'Students can talk freely with teachers.'
q6 = 'Students need help often got it from staff.'
q7 = 'Teachers are available for students'

;
proc format;
value sex

1 = 'Male'
2 = 'Female';

value SafeClose 1 = 'strongly disagree'


2 = 'disagree'
3 = 'neutral'
4 = 'agree'
5 = 'strongly agree';

value School

201 = 'Lebanon HS'


202 = 'Franklin HS'
211 = 'Howel HS'

;
proc print data = Final.climate label;
format SchoolCode School. Gender sex. q1-q7 SafeClose.;
var SchoolCode Gender q1-q7 safety close;
run;

proc contents;
proc means data = final.climate mean stddev;
by SchoolCode;
class gender;
2) log (8)(9)

3)
OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
4) 55
5) 56
proc contents;
6) 57
7)
8) NOTE: PROCEDURE CONTENTS used (Total process time):
9)
real time
0.13 seconds
10)
cpu time
0.12 seconds
11)
12) 57
! proc means data = final.climate mean stddev;
13)
14) 58
by SchoolCode;
15) 59
class gender;
16) 60
17) 61
18) 62
OPTIONS NONOTES NOSTIMER NOSOURCE
NOSYNTAXCHECK;
19) 74

2) Output (8)(9)

3) Code
libname cake '/folders/myfolders';
data pilots;
set sasuser.pilots1;
if ID = '1333' and gender = 'F' then ID = '1334';
If HomePhone = '718/383-1122 ' then HomePhone = '718/383-3555';
AddressLabel = ID;
length AreaCode $ 5.;
AreaCode = substr(HomePhone, 1 ,3);
midnum = substr(HomePhone, 5,3 );
endnum = substr(HomePhone,9,4 );
ageathired = floor((Hired-Birth)/365);
currentage = floor((Today()-Birth)/365);
newphonenum = cats(AreaCode, midnum, endnum);
;
proc format;
picture phonefmt;
20000000000 - 999999999999 = '999) 999-999' (prefix = '(');

proc format;
value $Address 1333 = 'Stamford, CT'
1739 = 'New York, NY'
1428 = 'Stamford, CT'
1404 = 'New York, NY'
1118 = 'New York, NY'
1905 = 'New York, NY'
1407 = 'MT. Vernon, NY'
1410 = 'Stamford, CT'
1439 = 'BridgePort, CT'
1545 = 'Stamford, CT'
1777 = 'New York, NY'
1106 = 'Stamford, CT'
1334 = 'Princeton, NJ'
1478 = 'New York, NY'
1556 = 'New York, NY'
1890 = 'New York, NY'
1107 = 'New York, NY'
1830 = 'Bridgeport, CT'
1928 = 'White Plains, NY'
1076 = 'New York, NY'
;
run;
proc print data = pilots label;
format AddressLabel $Address. HomePhone newphonenum $phonefmt. ;
var LastName Firstname City State AddressLabel HomePhone AreaCode
midnum endnum newphonenum ;
run;
3) Log

4)
OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
5) 55
6) 56
libname cake '/folders/myfolders';
7) NOTE: Libref CAKE refers to the same physical library as NAMES.
8) NOTE: Libref CAKE was successfully assigned as follows:
9)
Engine:
V9
10)
Physical Name: /folders/myfolders
11)
57
data pilots;
12)
58
set sasuser.pilots1;
13)
NOTE: Data file SASUSER.PILOTS1.DATA is in a format that is
native to another host, or the file encoding does not match the
session
14)
encoding. Cross Environment Data Access will be used,
which might require additional CPU resources and might reduce

15)
performance.
16)
59
if ID = '1333' and gender = 'F' then ID = '1334';
17)
60
If HomePhone = '718/383-1122 ' then HomePhone =
'718/383-3555';
18)
61
AddressLabel = ID;
19)
62
length AreaCode $ 5.;
20)
63
AreaCode = substr(HomePhone, 1 ,3);
21)
64
midnum = substr(HomePhone, 5,3 );
22)
65
endnum = substr(HomePhone,9,4 );
23)
66
ageathired = floor((Hired-Birth)/365);
24)
67
currentage = floor((Today()-Birth)/365);
25)
68
newphonenum = cats(AreaCode, midnum, endnum);
26)
69
;
27)
70
/*proc format;
28)
71
picture phonefmt; (default);
29)
72
20000000000 - 999999999999 = '999) 999-999'
(prefix = '(');*/
30)
73
31)
32)
NOTE: There were 20 observations read from the data set
SASUSER.PILOTS1.
33)
NOTE: The data set WORK.PILOTS has 20 observations and
18 variables.
34)
NOTE: DATA statement used (Total process time):
35)
real time
0.02 seconds
36)
cpu time
0.02 seconds
37)
38)
74
proc format;
39)
40)
75
value $Address 1333 = 'Stamford, CT'
41)
76
1739 = 'New York, NY'
42)
77
1428 = 'Stamford, CT'
43)
78
1404 = 'New York, NY'
44)
79
1118 = 'New York, NY'
45)
80
1905 = 'New York, NY'
46)
81
1407 = 'MT. Vernon, NY'
47)
82
1410 = 'Stamford, CT'
48)
83
1439 = 'BridgePort, CT'
49)
84
1545 = 'Stamford, CT'
50)
85
1777 = 'New York, NY'
51)
86
1106 = 'Stamford, CT'
52)
87
1334 = 'Princeton, NJ'
53)
88
1478 = 'New York, NY'

54)
89
1556 = 'New York, NY'
55)
90
1890 = 'New York, NY'
56)
91
1107 = 'New York, NY'
57)
92
1830 = 'Bridgeport, CT'
58)
93
1928 = 'White Plains, NY'
59)
94
1076 = 'New York, NY'
60)
95
61)
96
;
62)
NOTE: Format $ADDRESS is already on the library
WORK.FORMATS.
63)
NOTE: Format $ADDRESS has been output.
64)
97
run;
65)
66)
NOTE: PROCEDURE FORMAT used (Total process time):
67)
real time
0.00 seconds
68)
cpu time
0.00 seconds
69)
70)
71)
98
proc print data = pilots label;
72)
99
format AddressLabel $Address. HomePhone
newphonenum $phonefmt. ;
73)
100
var LastName Firstname City State AddressLabel
HomePhone AreaCode midnum endnum newphonenum ;
74)
101
run;
75)
76)
NOTE: There were 20 observations read from the data set
WORK.PILOTS.
77)
NOTE: PROCEDURE PRINT used (Total process time):
78)
real time
0.09 seconds
79)
cpu time
0.09 seconds
80)
81)
82)
102
83)
103
OPTIONS NONOTES NOSTIMER NOSOURCE
NOSYNTAXCHECK;
84)
115

3) output

4) Code
libname names '/folders/myfolders/';
data d1;
set sasuser.names;
data d2;
set sasuser.scores;
data d3;
merge d1 d2;
by idnum;
array key(16) $ 1 _temporary_('D' 'C' 'A' 'B' 'C' 'D' 'B' 'A' 'D' 'C' 'B' 'C' 'A' 'B'
'D' 'B');
array ans(16) q1-q16;
array score(16);
*input(q1-q16)($1.);
rawscore = 0;
do i = 1 to 16;
score(i) = (key(i) eq ans(i))*5;
rawscore + score(i);
end;

percentscore = 100*rawscore/80;
keep idnum rawscore percentscore;
drop i;
cards;
2005
A
2258
A
2338
C
2500
C
2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C
C
C
B
A
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C

6934
C
6938
C
6958
C
6959
C
7482
C
7594
C
7810
C
7845
C
7846
C
7848
C
7890
A
7892
A
7945
C
8093
C
8316
C
8573
C
8712
C
8734
C
8752
C
8855
C
8912
C
9281
C
9333

D
A
B
C
B
C
B
A
B
C
B
C
B
C
B
C
B
C
B
C
B
C
B
C
B
C
B
A
B
C
B
C
B
A
B
C
B
B
B
C
C
A
B
A
B

9365 B
C
B

C
C
B
C
C
C
C
B
C
C
C
C
C
C
C
C
C
C
C
A
C
C
C
A
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
B
C
C
C
C
B
C
C

C
B
D
A
B
B
B
B
B
A
B
C
B
A
B
A
C
C
B
B
C
A
B
A
B
A
C
B
B
A
B
B
C
A
C
B
C
C
C
A
B
A
B
B
C
A
C
A

C
D
C
D
D
C
B
D
A
D
C
D
A
A
C
D
C
B
D
C
C
D
D
C
D
B
D
A
B
D
D
D
D
D
D
B
D
D
D
D
C
D
D
C
D

C
B
B
B
C
B
C
A
C
B
C
B
C
B
C
B
C
B
C
B
C
B
C
B
C
B
C
B
C
B
C
B
C
C
C
B
C
A
C
D
B
C
C
B
C
B
C
B

9638
C
9651
C
9670
C
9673
C
9748
C
9836
C
9869
C

B
C
B
C
D
A
B
A
B
C
B
C
B
A

C
C
C
C
C
D
C
B
C
C
C
C
C
C

B
C
B
B
D
C
A
A
B
C
B
A
C
A

D
D
C
D
C
D
C
C
D
A
D
D
B
D

C
B
C
B
C
B
C
B
C
B
C
B
C
B

;
proc print; idnum idnum;
var rawscore percentscore;
run;
data d4;
set d1;
set d3;
fullname = First||Last;
select;
when (percentscore < 60) grade = 'E';
when (60 <=percentscore <=69.999) grade = 'D';
when (70<= percentscore <= 79.999) grade = 'C';
when (80 <= percentscore <=89.999 ) grade = 'B';
when (90<= percentscore<=100) grade = 'A';
end;
proc print data = d4;
var fullname type percentscore grade;
proc freq data = d4;
tables grade;
proc sort data = d4;
by type;
proc means data = d4 mean stddev;
by type;
var percentscore;
4) log

OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;


55
56
libname names '/folders/myfolders/';

NOTE: Libref NAMES was successfully assigned as follows:


Engine:
V9
Physical Name: /folders/myfolders
57
data d1;
58
set sasuser.names;
NOTE: Data file SASUSER.NAMES.DATA is in a format that is native to
another host, or the file encoding does not match the session
encoding. Cross Environment Data Access will be used, which might
require additional CPU resources and might reduce
performance.
NOTE: There were 76 observations read from the data set SASUSER.NAMES.
NOTE: The data set WORK.D1 has 76 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time
0.01 seconds
cpu time
0.00 seconds
59

data d2;

60
set sasuser.scores;
NOTE: Data file SASUSER.SCORES.DATA is in a format that is native to
another host, or the file encoding does not match the session
encoding. Cross Environment Data Access will be used, which might
require additional CPU resources and might reduce
performance.
NOTE: There were 76 observations read from the data set SASUSER.SCORES.
NOTE: The data set WORK.D2 has 76 observations and 18 variables.
NOTE: DATA statement used (Total process time):
real time
0.02 seconds
cpu time
0.02 seconds
61

data d3;

62
merge d1 d2;
63
by idnum;
64
65
array key(16) $ 1 _temporary_('D' 'C' 'A' 'B' 'C' 'D' 'B' 'A' 'D' 'C' 'B' 'C'
'A' 'B' 'D' 'B');
66
array ans(16) q1-q16;
67
array score(16);
68
*input(q1-q16)($1.);
69
rawscore = 0;
70
do i = 1 to 16;

71
72
73
74
75
76
77
78

score(i) = (key(i) eq ans(i))*5;


rawscore + score(i);
end;
percentscore = 100*rawscore/80;
keep idnum rawscore percentscore;
drop i;
cards;

NOTE: There were 76 observations read from the data set WORK.D1.
NOTE: There were 76 observations read from the data set WORK.D2.
NOTE: The data set WORK.D3 has 76 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time
0.01 seconds
cpu time
0.02 seconds
155
156
157
158

proc print; idnum idnum;


_____
1
WARNING 1-322: Assuming the symbol ID was misspelled as idnum.
159
var rawscore percentscore;
160
run;
NOTE: There were 76 observations read from the data set WORK.D3.
NOTE: PROCEDURE PRINT used (Total process time):
real time
0.10 seconds
cpu time
0.10 seconds
161
162
163
164
165
166
167
168
169
170
171

data d4;
set d1;
set d3;
fullname = First||Last;
select;
when (percentscore < 60) grade = 'E';
when (60 <=percentscore <=69.999) grade = 'D';
when (70<= percentscore <= 79.999) grade = 'C';
when (80 <= percentscore <=89.999 ) grade = 'B';
when (90<= percentscore<=100) grade = 'A';
end;

172
NOTE: There were 76 observations read from the data set WORK.D1.
NOTE: There were 76 observations read from the data set WORK.D3.
NOTE: The data set WORK.D4 has 76 observations and 8 variables.
NOTE: DATA statement used (Total process time):
real time
0.01 seconds
cpu time
0.01 seconds
172
173
174

! proc print data = d4;


var fullname type percentscore grade;

NOTE: There were 76 observations read from the data set WORK.D4.
NOTE: PROCEDURE PRINT used (Total process time):
real time
0.12 seconds
cpu time
0.11 seconds
174
175
176

! proc freq data = d4;


tables grade;

NOTE: There were 76 observations read from the data set WORK.D4.
NOTE: PROCEDURE FREQ used (Total process time):
real time
0.03 seconds
cpu time
0.02 seconds
176
177
178

! proc sort data = d4;


by type;

NOTE: There were 76 observations read from the data set WORK.D4.
NOTE: The data set WORK.D4 has 76 observations and 8 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time
0.00 seconds
cpu time
0.01 seconds
178
179
180
181

! proc means data = d4 mean stddev;


by type;
var percentscore;

182
183
184
196

OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

4) output

You might also like