You are on page 1of 7

Test1

1.1)code
/* I completed the assignment at home because of restricted library hours and fo
r convenience.
The second one is the only way I can import raw data into SAS Un
iversityEdition*/
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.2)
P1Q2) 2. height-in-cm is not valid because other than underscore special charact
ers 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 ca
n only be 8 or less characters in length.
4. - and 5. 7kg_Tom are not valid libref names because they are not va
lid 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_parkin
g_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) code
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)
92

! proc contents;

93
NOTE: PROCEDURE CONTENTS used (Total process time):
real time
0.07 seconds
cpu time
0.07 seconds
93
94
95
96

! proc means data = final.climate mean stddev;


by SchoolCode;
class gender;

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);
ageathired = floor((Hired-Birth)/365);
currentage = floor((Today()-Birth)/365);
proc format;
picture new
low-high = '999-999-9999' ;
proc format;
value $Address 1333 = 'Stamford, CT'
1739 =
1428 =
1404 =
1118 =
1905 =
1407 =
1410 =
1439 =
1545 =
1777 =
1106 =
1334 =
1478 =
1556 =
1890 =
1107 =
1830 =
1928 =
1076 =

'New York, NY'


'Stamford, CT'
'New York, NY'
'New York, NY'
'New York, NY'
'MT. Vernon, NY'
'Stamford, CT'
'BridgePort, CT'
'Stamford, CT'
'New York, NY'
'Stamford, CT'
'Princeton, NJ'
'New York, NY'
'New York, NY'
'New York, NY'
'New York, NY'
'Bridgeport, CT'
'White Plains, NY'
'New York, NY'

;
run;
proc print data = pilots label;
format AddressLabel $Address. HomePhone $new. ;
var LastName Firstname City State AddressLabel HomePhone ;
run;
3b) log
1
OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
55
56
libname cake '/folders/myfolders';
NOTE: Libref CAKE refers to the same physical library as NAMES.
NOTE: Libref CAKE was successfully assigned as follows:
Engine:
V9
Physical Name: /folders/myfolders
57
data pilots;
58
set sasuser.pilots1;
NOTE: Data file SASUSER.PILOTS1.DATA is in a format that is native to another h
ost, 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.
59
if ID = '1333' and gender = 'F' then ID = '1334';
60
If HomePhone = '718/383-1122 ' then HomePhone = '718/383-3555';
61
AddressLabel = ID;
62
/*length AreaCode $ 5.;*/
63
AreaCode = substr(HomePhone, 1 ,3);
64
ageathired = floor((Hired-Birth)/365);
65
currentage = floor((Today()-Birth)/365);
NOTE: There were 20 observations read from the data set SASUSER.PILOTS1.
NOTE: The data set WORK.PILOTS has 20 observations and 15 variables.
NOTE: DATA statement used (Total process time):
real time
0.01 seconds
cpu time
0.02 seconds
66

proc format;

67
67
! picture new
68
low-high = '999-999-9999' ;
NOTE: Format NEW is already on the library WORK.FORMATS.
NOTE: Format NEW has been output.
69
NOTE: PROCEDURE FORMAT used (Total process time):
real time
0.00 seconds
cpu time
0.00 seconds
70
71
72
73
74
75
76

proc format;
value
1739 =
1428 =
1404 =
1118 =
1905 =

$Address 1333 = 'Stamford, CT'


'New York, NY'
'Stamford, CT'
'New York, NY'
'New York, NY'
'New York, NY'

77
1407 = 'MT. Vernon, NY'
78
1410 = 'Stamford, CT'
79
1439 = 'BridgePort, CT'
80
1545 = 'Stamford, CT'
81
1777 = 'New York, NY'
82
1106 = 'Stamford, CT'
83
1334 = 'Princeton, NJ'
84
1478 = 'New York, NY'
85
1556 = 'New York, NY'
86
1890 = 'New York, NY'
87
1107 = 'New York, NY'
88
1830 = 'Bridgeport, CT'
89
1928 = 'White Plains, NY'
90
1076 = 'New York, NY'
91
92
;
NOTE: Format $ADDRESS is already on the library WORK.FORMATS.
NOTE: Format $ADDRESS has been output.
93
run;
NOTE: PROCEDURE FORMAT used (Total process time):
real time
0.00 seconds
cpu time
0.01 seconds
94
95
96
97

proc print data = pilots label;


format AddressLabel $Address. HomePhone $new. ;
var LastName Firstname City State AddressLabel HomePhone ;
run;

NOTE: There were 20 observations read from the data set WORK.PILOTS.
NOTE: PROCEDURE PRINT used (Total process time):
real time
0.07 seconds
cpu time
0.07 seconds
98
99
111

OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

4) code
libname names '/folders/myfolders/';
data d1;
set sasuser.names;
data d2;
set sasuser.scores;
data d3;
merge d1 d2;
by idnum;
percentscore = percent*5;
fullname = catx('', first, last);
array key(16) $ 1 _temporary_;
array ans(16) $1;
array score(16) _temporary_;
If _N_ = 1 then
do i = 1 to 16;
input key(i) @;
end;
input ID $ @5 (ans1-ans16)($1.);

rawscore = 0;
do i = 1 to 16;
score(i) = ans(i) eq key(i);
rawscore + score(i);
end;
percent = 100*rawscore/16;
drop i;
datalines;
D, C, A B C D B A D C B C A B D B
001 B C B B C C B B D C A C C A D B
002 B C C C C C B D B C A C C A C B
003 B C B A C B B C D C C C C C D B
004 B C B C C C B D D C C A C A D B
005 B C C B C C B D C C C A C B C B
006 C C C D C C B D C C C C C C A D
007 B C C D C C B B B B C A A C A D
008 B C B B C C B D C C C C C A D B
009 B C B B C C B D C C C A C A D B
010 B C B B C C B B D C C C C A D B
011 B A B D A C B B D D C C A C B C
012 B C C C C C B D D C C C C C D B
013 B C B B C C B B B C C C C C D B
014 B C B D C C B B B C C A C B D B
015 B C B B C C B D D C C A C B D B
016 B C B B C C B D C C C C B C C B
017 A C C B C C B D D C C C C B D B
018 B C A B C A B B D C C C B B C D
019 B C B B C B B D D B C C C A D B
020 B C B D C C B D D C C C C B D C
021 C C C D C C B B C B C C C A D B
022 B C B B C C B D B C C C C A D B
023
024 B C C C C C B D A C A A C B D B
025 C C B B C A B B C C A C B D B
026 B C C D C C B D D C C C C A C B
027 D C C D C C B D D B C A C A D B
028 B C B C C C B A D C C C C B D B
029 B C A D C C B C D B C C C B D B
030 B C C B C C B D C C C C C B D A
031 B C D C C C B C D C C A C A D B
032 B C C C C C B D C C C C B A C B
033 B D C C C B B B C C C A A D B
034 B C B B C C B B D C C C C B D B
035 B C C B C C B C D C C A C B D B
036 A C B C C C A B D C C C C C B D
037 B C A D C C B B B C C A C A D B
038 B C B C C C B C C B C C C C D B
039 B C C C C C B D C B C C C A C B
040 D C C C C C B B C C C C A C B
041 B C B D C C A C D C C C C C D B
042 B C C C C C B A D A C C C A D B
043 B C C D C C B C D B C A C A C B
044 B C C D C C B B D D C C C B D B
045 D C C C C C B B B C C A C B D B
046 B B D C B C B D B C C C C A D B
047 B C B D C B B C D C C C C B C B
048 B C B B C C B A D C C A B B D A
049 B C B A C C B C D C C C C A D B
050 B C B C C C B B D C C C C C D B
051 B C B A C C B B D C C C C A A B

052
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
;

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

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

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

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

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

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

proc print data = d3;


ID ID;
run;

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

You might also like