Statistics 479 Assignment #1 Suggested Solution ...

advertisement
Statistics 479
Assignment #1 Suggested Solution
Fall 2013
Problem#2
a) input statement
b) datalines statement
c) name, type, length, position, informat, format, label
format, label, informat, length, and the attrib statements
d) infile “U:\Documents\Stat479\survey.txt”;
Note: infile statement identifies the external file containing raw
input data to be read by an input statement in your data step.
e) list input:
input id name $ age height weight;
2157 Williams 18 68.5 146
formatted input:
input (id name age height weight)(4. $10. 2. 3.1 3.);
2157Williams 18685146
column input:
input id 1-4 name $ 5-14 age 15-16 height 17-19 .1 weight 2022;
2157Williams 18685146
f). data reorder;
set sales;
if Region=’Midwest’ and Quantity<3476.25;
run;
or
data reorder;
set sales;
if Region^=’Midwest’ or Quantity >= 3476.25 then delete;
run;
g). 3 data steps in Example B1
SAS data sets created are: third, fourth, and fifth
All data sets are temporary
third : 3 Variables w x y and 3 observations
fourth: 3 Variables x y z and 3 observations
fifth : 4 Variables w x y z and 6 observations
h). SAS will store a date as the number of days since Jan 1,1960.
If the date is before Jan 1, 1960, it stores the negative of the
number of days between that date and Jan 1,1960.
SAS will store a time as the number of seconds since midnight the same
day.
For more information:
Go to the SAS online documentation (HTML version) webpage using link.
SAS Language Reference: Concepts. Use the Search this document tab,
and search for: SAS dates Click on
Dates, Times, and Intervals: About SAS Date, Time, and Datetime Values
i). delete - tells SAS not to write the current values in the
program data vector into the SAS data set, as a
new observation, i.e., stop processing the current
data line
drop - tells SAS not to include the named variables in the
SAS data set being created.
j). Input Buffer:
----+----1----+----2----+----3
Knights John
7 7 7
Program Data Vector:
TeamName ParticipantName Event1 Event2 Event3 TeamTotal _N_ _ERROR_
Knights
John
7
7
7
67
3
0
Note: _N_ and _ERROR_ are examples of SAS automatic variables.
Read details of the current example further (p. 326 of Chapter
20) to learn what their values are.
SAS Data Set Total_Points (right after processing of data line 3)
looks like:
ParticipantName Event1 Event2 Event3
Sue
Jane
John
6
9
7
8
7
7
8
8
7
TeamTotal
22
46
67
OR the last observations written is
ParticipantName Event1 Event2 Event3
John
7
7
7
TeamTotal
67
Important Learning Point:
The variable TeamTotal is not initialized to a missing value as one
might expect, at the beginning of each iteration of the data step
because the value created by this type of accumulation or sum
statement is automatically retained (i.e.,not initialized to a missing
value when SAS returns to the top of the data step). We talked about
the retain statement as illustrated in SAS Example A9.
Problem#3
data stat101;
input Id Major $5. Year Quiz Exam1 Exam2 Lab Final;
Score=.2*Quiz+.2*Exam1+.2*Exam2+.1*Lab+.2*Final;
if Score >=90 then Grade='A';
else if 80<=Score<90 then Grade='B';
else if 70<=Score<80 then Grade='C';
else if 60<=Score<70 then Grade='D';
else if Score<60 then Grade='F';
datalines;
5109
7391
4720
4587
6753
5921
5632
4587
3490
4186
5065
5712
8091
7126
2308
2540
3518
4075
3907
4013
4456
7324
0746
Psych
Econ
Math
Stat
Stat
Psych
Phys
Biol
Biol
Math
Econ
Acct
Stat
Stat
Chem
Phys
Mteor
A Ecl
C E
Econ
Acct
Psych
Chem
4
4
4
3
4
3
3
4
2
4
4
4
4
3
3
3
3
3
4
2
4
3
4
50 93 93 98 162
49 95 98 97 175
39 63 84 95 95
46 92 96 88 150
45 100 98 96 191
44 98 100 85 175
41 86 86 94 138
50 100 100 99 166
50 95 97 96 162
48 71 100 97 143
45 64 93 93 147
41 92 91 90 150
34 50 86 95 129
20 64 82 63 94
33 44 64 89 74
45 99 98 97 152
42 68 51 93 110
40 97 100 88 75
44 80 99 99 134
48 86 87 96 165
36 83 88 91 154
42 78 98 95 102
48 84 84 97 154
;
ods rtf file="U:\Documents\Stat479\lab1Prob3.rtf";
proc print data=stat101;
run;
data intern;
set stat101;
if (Year=3|Year=4) and Grade='A';
run;
proc print data=intern;
var Major Year Score;
id Id;
run;
proc print data=stat101;
where (Year=3|Year=4) and Grade='A';
var Major Year Score;
id Id;
run;
ods rtf close;
Download