Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

STA 306

Fall 2023

Homework # 2

Due:  Thurs., Sept.  28 by 11:59pm ET

Directions:  Submit your solutions through Gradescope by the due date and time. Your submission should be well-organized as follows:  for  each part,  include  (i) any relevant SAS code used;  (ii) any relevant SAS output; and (iii) a short answer to any question that is asked (if applicable).  Unless otherwise stated, use an α = 0.05 level of significance where applicable.

Problem  1.  The table below contains employee ID, salary, and job class for a random sample of employees:

emp__id

salary

job__class

y12345

75000

3

y11122

125000

1

y09754

175000

2

y07345

50000

3

(a)  Read the above data into SAS, and use appropriate if-then-else if statements to create a new variable called bonus that is computed as follows: the amount of the bonus is $1000 plus 10% of salary for job class 1, $750 plus 7.5% of salary for job class 2, and $500 plus 5% of salary for job class 3.

(b)  Add the salary and bonus together to create a new variable called total_salary.

(c)  Use proc print to display the contents of the data set(s) created in this problem.

Problem  2.  In this problem, use the SAS data set hosp_data that can be created with the following code:

data hosp_data;

informat id $3. gender $1. dob dos mmddyy8.;

input id gender dob dos los sbp dbp hr;

format dob dos mmddyy10.;

cards;

1M10/21/763/17/17121307076

2F11/1/853/1/17401206478

3M6/6/901/1/1731109063

4F12/21/862/12/17518011059

;

run;

This data set contains patient ID, gender, date ofbirth, date of service, length of stay, systolic blood pressure, diastolic blood pressure, and heart rate (in beats per minute) for a random sample of patients at a certain hospital.

(a)  Create a data set that contains the variables listed above, as well as the following additional variables:

•  avg_bp: the average of each patient’s systolic and diastolic blood pressures

•  pat_age: patient’s age (rounded down to a whole year) on date of service.  Note that the age in days can be obtained by subtracting date of birth from date of service. Use 365.25 days in a year, and then round down.

•  beats_per_15: patient heart rate per 15 seconds based on their heart rate in beats per minute, rounded to the nearest tenth

(b)  Use proc print to display the contents of the data set.

Problem  3.  Use the SAS data set lake_temps.sas7bdat for this question, which contains the temper- ature of the water in Lake Erie from a variety of sites in the United States and Canada on a certain day.

There are four variables in this data set:  site id, country, temp_f, and temp_c.  Temperatures taken in the United States are recorded in degrees Fahrenheit, while temperatures taken in Canada are recorded in degrees Celsius.  Note that one of the sites was inactive on a particular day, and the data set contains no temperatures for this day.

(a)  The variable site_id is made up of the last two digits of the year the site entered the temperature tracking program, followed by a four digit city code.  Create two new variables, year and city_code, which contain these two pieces of information separately.   Be sure to express each year in the form ‘20XX’.

(b)  Create a new variable called deg_c that contains each temperature in degrees Celsius.  You can use the relationship

Celsius =  (Fahrenheit − 32)

to convert degrees Fahrenheit to degrees Celsius where needed.  Round to the nearest tenth.

(c)  Use an appropriate SAS procedure to obtain the 20th  and 80th  percentiles of the new variable deg_c.

(d)  Within a single data step, write some code which uses the variable deg_c to do the following:

•  outputs observations with low temperatures (below 20th percentile) to a data set called low_temps;

•  outputs observations with medium temperatures (between 20th  and 80th  percentiles, inclusive) to a data set called medium_temps;

•  outputs observations with high temperatures (above 80th percentile) to a data set called high_temps;

•  outputs observations with missing temperatures to a data set called missing_temps.

Be sure any observation with a missing value of deg_c appears only in the missing_temps data set.

(e)  Use proc print to display the contents of the data sets created in this problem.