Statistics 479 Assignment #2 ...

advertisement
Statistics 479
Assignment #2
1. a)
Age
18
.
23
Id
1906
3045
2119
Gender
M
F
M
GPA
3.15
3.85
3.72
Id
Quiz1 Quiz2 Quiz3 Quiz4
3490 432 16
798 2
1978 57
3
6
84
c) Obs
1
2
3
Id
Pulse Weight
L4WP 85
251.7
M5XQ .
142.3
79
114.5
Obs
1
2
Fall 2013
SAT
720
683
775
b) Obs
1
2
d)
Answer Key
Pushups
28
32
19
Name
Id
Wilson
3974
Worthington 1 598
Visit
-4420
9693
2.
Obs
1
2
3
4
5
6







Score
47
49
50
52
55
.
Grade
Fail
Fail
Pass
Pass
Fail
Rating
.
.
.
0.2
0.5
.
read-in a value into variable score (in PDV) using List Input.
the current line-of-data is held for further reading because of
the 'trailing @@'.
executes SAS program statements depending on value of score.
if the value of score > 50 set values for Grade="Pass" and Rating
= (value of score – 50)/10 in the PDV.
if the value of score < 50 set value for Grade="Fail" and the
value for Rating remains a missing value "." with which it was
initialized in the PDV. Then SAS returns to the top of the data
step.
if the value of score = 50 values for both Grade and the value
for Rating remain missing values. Note that a missing value for a
character variable is a blank.
after one of the if statements is executed SAS goes to the end of
the data step, writes an observation to the data set class and
returns to the input statement.
3. a)
x
1
4
5
y
1.25
4.57
5.68
b) x
1
2
3
4
5
y
1.25
2.34
3.46
4.57
5.68
c)
x
1.00
4.00
5.00
5.68
d) x
1
4
y
1.25
4.57
z
2
5
Explanation:
a)Reads two values from a dataline then goes to the next line,
using list input. Continues to read the current dataline until
a value is found; else goes to the next line to read a value.
b)Tries to repeatedly read a pair of values. If no values are
available on the current line gets values from the next line.
c)Reads one value from each data line.
d)Uses list input read 3 values from a dataline then goes to
the next line. Goes to the next line if not enough value
in the current data line. If end-of-file reached, while
reading any of the 3 values, then the current PDV values
will not be written to the dataset.
4.
a) -.6666667
f) 1
g) 1
b) 5.5 c) -1.0
d) 10.5 e) 13.0
h) 1 i) 0
j) 0 k) 0 l) 1 m) 0
5.
w.d informat:
Ignores trailing blanks; fills leading blanks to a length w; If period
occurs in the data within field (i.e, within w columns) specified format
is ignored.
miles
.01
.12
1.23
12.34
123.45
1.00
12.00
12.30
1234.00
6.
Dept
parts
parts
parts
parts
...
...
...
tools
...
...
...
repairs
Id
176
176
176
217
..
..
..
124
..
..
..
26
Year
1982
1983
1984
1982
...
...
...
1982
...
...
...
1984
Sales
3500
2500
800
2644
...
...
...
5672
...
...
...
8425
PDV
Dept
parts
Id
176
P82 P83
3500 2500
P84
800
7. This answer provides
question:
Year
1984
Sales
800
_N_
1
_Error_
0
*more* information than required by the
The data step begins; Variables X1, X2, X3 and X4 in the program data
vector (PDV) are initialized to missing values:







reads-in values 3, 4 and 5 into variables X1, X2 and X3 using List
Input style.
the current line-of-data is held for further reading because of the
'trailing @@'.
a new value of 15 is computed as the new value of variable X3 in
the PDV.
a new value of 2 is computed as the new value of variable X4 in the
PDV.
reached end of the data step. Writes an observation into data set
using current values in PDV. Variable X1 and X2 will not be
written.
re-initialize PDV to missing values and goes back to the input
statement and reads the next 2 values in the same data line.
continues until end-of-file (i.e. end-of-data). SAS closes data
set; goes to next step.
PDV (just before writing first observation)
X1
3
X2
4
X3
15
X4
2
_N_
1
_ERROR_
0
Output Produced:
Obs
1
2
3
4
8.
X3
6
5
3
.
X4
2
3
1
4
Parts
Obs
1
2
3
(a)
Name
Score1
Joe
11
Michael
13
Susan
14
Score2
32
29
27
Score3
76
82
74
Parts
Obs
1
2
3
(b)
name
Score1
Joe
11
Michael 13
Susan
14
Score2
32
29
27
Score3
76
82
74
Team
red
blue
green
Part (c) insert a period in the data where a value would have been
entered for score2 in data line 2.
Part (d) the input statement still works because in list input
style it will keep looking for values by moving the pointer to the
next line of data.
Part (e) total=score1+score2+score3;
datalines.
Insert between input and
Part (f) insert the following statement before input statement:
infile “M:\stat479\class\test.txt”;
9.
data perform;
Input Grade $2. @;
if Grade="09"|Grade="10" then
input Id $4. GPA 3.2 Science 2. English 2.;
else
input Id $4. GPA 3.2 Science 2. Math 2. English 2.;
datalines;
0962432736578
118091315736792
0945712817859
125916294847689
1076543057182
112479329697883
;
proc print;
run;
Download