SAS代写 STAT2005

Microsoft Word – Assignment 4.docx

STAT2005 Programming Languages for Statistics Assignment 4
Due: 5pm, 5 December, 2018

1. Write SAS statement(s) for each of the following tasks:
(a) Set X1 to be the number of days in YEAR, a numeric variable for year, e.g. If YEAR =

2000, X1 = 366.

(b) X2 is a character variable for name. It contains two to three words, with the first word being the last name. Define NAME to be the name with the given name presented by the initials, e.g. if X2 = ‘Chan Tai Man’, then NAME = ‘Chan T. M.’ and if X2 = ‘Chan Keung’, then NAME = ‘Chan K.’.

(c) SetX3to be the larger root of ax2 + bx + c = 0 if the polynomial has real roots, and setX3 to a missing value otherwise.

(d) Consider ∆ABC with ∠ACB = 52o. Denote the length of BC by a, the length of AC by b, and the length of AB by c. Find c given the values of a and b.

(e) X4 is a character variable of length 1. Replace the last non‐blank character of Y by X4; set Y=X4ifY = “”.

2. Consider the data file Blood.sas7bdat.

(a) Create two temporary SAS data sets called Subset_A and Subset_B. Include in both of these data sets a variable called Combined equal to .001 times WBC plus RBC. Subset_A should consist of observations from Blood where Gender is equal to Female and BloodType is equal to AB. Subset_B should consist of all observations from Blood where Gender is equal to Female, BloodType is equal to AB, and Combined is greater than or equal to 14.

(b) Create two temporary SAS data sets by selecting all subjects with cholesterol levels (Chol) below 100. Place the male subjects in Lowmale and the female subjects in Lowfemale. Do this using a single DATA step.

3. Run the program here to create a temporary SAS data set called Vitals.

DATA VITALS;

INPUT ID $3. AGE PULSE SBP DBP;

LABEL SBP = "SYSTOLIC BLOOD PRESSURE"
DBP = "DIASTOLIC BLOOD PRESSURE";

DATALINES;

001 23 68 120 80
002 55 72 188 96
003 78 82 200 100
004 18 58 110 70
005 43 52 120 82
006 37 74 150 98
007 . 82 140 100

RUN;

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. Write a PROC PRINT statement to produce the following output.

4. Merge the data sets Purchase.sas7bdat and Inventory.sas7bdat to create a new temporary SAS data set (Pur_Price) where the Price value found in the Inventory data set is added to each observation in the Purchase data set, based on the Model number (Model). There are some models in the Inventory data set that were not purchased (and, therefore, are not in the Purchase data set). Do not include these models in your new data set. Based on the variable Quantity in the Purchase data set, compute a total cost (TotalCost) equal to Quantity times Price in this data set as well. The output is shown below.

You should submit a file asg4.sas via Blackboard, which contains all the SAS codes you use to finish this assignment. The codes should be commented as clearly as possible. Written work (if any) should also be submitted to the assignment drop‐box.