Saturday, 19 September 2015

SAS Solutions from Ron Cody

Problem Statement:

7-2 Using the SAS data set Hosp, use PROC PRINT to list observations for Subject
values of 5, 100, 150, and 200. Do this twice, once using OR operators and once
using the IN operator.


Code





Output:       HERE IS THE OUTPUT








Problem Statement:

8-1 Run the program here to create a temporary SAS data set called Vitals:




Using this data set, create a new data set (NewVitals) with the following new
variables:
For subjects less than 50 years of age:
If Pulse is less than 70, set PulseGroup equal to Low;
otherwise, set PulseGroup equal to High.
If SBP is less than 130, set SBPGroup equal to Low;
otherwise, set SBPGroup equal to High.
For subjects greater than or equal to 50 years of age:
If Pulse is less than 74, set PulseGroup equal to Low;
otherwise, set PulseGroup equal to High.
If SBP is less than 140, set SBPGroup equal to Low;
otherwise, set SBPGroup equal to High.
You may assume there are no missing values for Pulse or SBP.


Code








Output:     HERE IS THE OUTPUT











Problem Statement:

9-12 You want to see each patient in the Medical data set on the same day of the week 5
weeks after they visited the clinic (the variable name is VisitDate). Provide a listing
of the patient number (Patno), the visit date, and the date for the return visit.


Code







Output:      HERE IS THE OUTPUT









Problem Statement

10-2 Using the SAS data set Hosp, create a temporary SAS data set called Monday2002,
consisting of observations from Hosp where the admission date (AdmitDate) falls on
a Monday and the year is 2002. Include in this new data set a variable called Age,
computed as the person’s age as of the admission date, rounded to the nearest year.


Code:     HERE IS THE OUTPUT






Output:     HERE IS THE OUTPUT










Problem Statement:

11-8 Create a temporary SAS data set (Random) consisting of 1,000 observations, each
with a random integer from 1 to 5. Make sure that all integers in the range are
equally likely. Run PROC FREQ to test this assumption.


Code






Output:       HERE IS THE OUTPUT










Problem Statement:

12-2 Using the data set Mixed, create a temporary SAS data set (also called Mixed) with
the following new variables:
a. NameLow – Name in lowercase
b. NameProp – Name in proper case
c. (Bonus – difficult) NameHard – Name in proper case without using the
PROPCASE function


Code






Output:        HERE IS THE OUTPUT












Problem Statement:

12-14 List all patients in the Medical data set where the word antibiotics is in the
comment field (Comment).


Code:




Output:          HERE IS THE OUTPUT










Problem Statement:

13-1 Using the SAS data set Survey1, create a new, temporary SAS data set (Survey1)
where the values of the variables Ques1–Ques5 are reversed as follows: 1 􀃆 5; 2
􀃆 4; 3 􀃆 3; 4 􀃆 2; 5 􀃆 1.


Code






Output:      HERE IS THE OUTPUT









Problem Statement:

14-3 Use PROC PRINT (without any DATA steps) to create a listing like the one here.

Note: The variables in the Hosp data set are Subject, AdmitDate (Admission Date),
DischrDate (Discharge Date), and DOB (Date of Birth).


Code








Output:     HERE IS THE OUTPUT










Problem Statement:

15-5 Using the SAS data set BloodPressure, produce a report showing Gender and Age,
along with a new variable called AgeGroup. Values of AgeGroup are <= 50 or
> 50 depending on the value of Age. Label this variable “Age Group.” Your report
should look like this:




Output:  HERE IS THE OUTPUT