Professional Documents
Culture Documents
SAS Lab 13
Files needed:
Grades.txt
Main.sas7dbat
Copy all the above files into a folder on your flash drive. Create a SAS library called “lab” that
references this folder. (libname lab “g:\lab”;)
1. Run the unfinished code below which creates a SAS data set called “data1”. Notice there are a
lot of missing values.
a. Create a variable called MissCounter that gives a running total of the missing values
for “data1” as they are read in. Use the increment counter we discussed in the lecture
for this problem.
Unfinished Code
*Lab 13 – Problem 1;
data lab.data1;
datalines;
2 . 7 . . 3 5 . . 4 . 3 . 4
;
run;
Finished Code
*Lab 13 – Problem 1;
2. Change the following unfinished code in Red to perform the same actions, but using “do
groups” instead of if then statements.
Unfinished Code
*Lab 13 – Problem 2;
data lab.grades;
length Gender $ 1 Quiz $ 2 AgeGrp $ 13;
infile 'g:\lab14\grades.txt' missover;
1
input Age Gender Midterm Quiz FinalExam;
if missing(Age) then delete;
if Age le 39 then Agegrp = 'Younger group';
if Age le 39 then Grade = .4*Midterm + .6*FinalExam;
if Age gt 39 then Agegrp = 'Older group';
if Age gt 39 then Grade = (Midterm + FinalExam)/2;
run;
Finished Code
*Lab 13 – Problem 2;
data lab.grades;
end;
end;
run;
run;
2
3. Using the code in the unfinished codes section below and the SAS data set called “Main”,
a. Recode the following variables: ormoth, orracem, orfath, & orracef so that any value
equal to 9 is recoded to a missing value (.). Use the SAS array procedures to perform
this recoding.
b. Show your results in a set of frequency tables for these 4 variables.
Unfinished Code
*Lab 13 – Problem 3;
data lab.mainclean;
set lab.main;
Finished Code
*Lab 13 – Problem 3;
4. Create a SAS data set called “hundred” using a do loop to create a 100 observations.
a. Add a simulated variable called “length” which is normally distributed and has a mean of
20 and a standard deviation of 4.
b. Add another simulated variable call “height” which is uniformly distributed with values
between 0 and 1.
Unfinished Code
*Lab 13 – Problem 4;
data
run;
Finished Code
*Lab 13 – Problem 4;
5. Using the code in the unfinished code section below, read in the 3 Fahrenheit temperatures
provided. Create variable called Celsius that is related to Fahrenheit by the following
equation: Celsius{Hour} = (Fahren{Hour} - 32)/1.8; Use a do loop to create this
Celsius variable.
Unfinished Code
*Lab 13 – Problem 5;
data lab.temp;
input Fahren1-Fahren3 @@;
datalines;
32 72 100
;
run;
Finished Code
*Lab 13 – Problem 5;