QuestionQuestion

Problem 4.
Suppose you have collected the following information on some participants in a diet program:
Variable Name Description Variable type Starting column Ending column
Subj Subject no. Character 1 3
Height Height (inches) Character 4 5
Wt_init Initial weight (lbs.) Numeric 6 8
Wt_final Final weight (lbs.) Numeric 9 11
Using the above information, read the data that is contained in dietdata.dat into a temporary SAS data set called dietdata. Then, add the following three new variables to the data set:
• bmi_init, the subject's initial body mass index
• bmi_final, the subject's final body mass index
• bmi_diff, the change in the subject's body mass index
Body mass index is a person's weight (in kilograms) divided by their height (in meters) squared [Note: only the denominator of the ratio is squared, not the entire ratio, i.e. the units of BMI are kg/m2]. To convert pounds to kilograms, divide pounds by 2.2. To convert inches to meters, multiply inches by 0.0254. Note that large values of body mass index indicate more overweight individuals. Therefore, if the diet program is working, bmi_diff should be negative. Oh, and of course, explicitly convert height to a numeric variable before using it in your calculations. Print your final data set, setting your page size to 58 and line size to 80.
2. Suppose the value of variable abc is 10, the value of variable def is 5, the value of variable ghi is 2, and the variable of jkl is 4. Using an INPUT statement in conjunction with a DATALINES statement, read the values of these four variables into a temporary SAS dataset called temp (which contains only one observation of data). Then, create the following five new variables:
• one, which equals abc plus def minus ghi plus jkl (that is, use no parentheses)
• two, which equals the sum of ghi and jkl subtracted from the sum of abc and def (that is, use two sets of parentheses)
• three, which equals the sum of three things: abc, jkl, and the difference in def and ghi (that is, use one set of parentheses)
• four, which equals the sum of three things: abc, jkl, and def divided by ghi (that is, use no parentheses)
• five, which equals the sum of abc and def divided by the sum of ghi and jkl (that is, use two sets of parentheses)
Print your resulting data set, setting your page size to 58 and line size to 80. In doing so, appreciate the value and importance of using parentheses to write arithmetic operations in your SAS programs.

Problem 5.
Dual-photon absorptiometry (DPA) is a method to measure bone mineral density and evaluate the quality of bone being considered for transplant. The DPA technique is expensive and often unavailable. Therefore, an alternative method is to use a bone score based on four less expensive bone quality measures: i) Singh index (singh), ii) CC ratio (ccratio), iii) calcar width (calcar), and iv) cortical shaft index (csi). The data stored in Bonescor2.dat were collected by Renee Smith of the Bone and Joint Research Lab at the VA Medical Center in Salt Lake City, UT. She used the data to compare the two methods of quantifying bone mineral density. We will use the data here to reinforce the concept of programming for missing values. Oh ... please bear with the details of this homework problem ... it seems longer than it really is.
a. First, read the bone data arising from 30 subjects that is stored in Bonescor2.dat into a temporary data set called bonescore1. The first column contains the variable singh, the second column contains the variable ccratio, the third column contains the variable csi, and the fourth column contains the variable calcar. The fifth column contains the bone score (bone) that Renee Smith formulated from the first four measures, and the sixth column contains the gold standard dual-photon absorptiometry (dpa) measures. When reading in the data, take note that there are a few missing values in the data set.
After, you've successfully read in the data, create four new variables in your bonescore1 data set: flag1, flag2, flag3, and flag4 according to the following specifications:
Value of flag variable
Flag variable 1 2 3
flag1 singh ≤ 4 4 < singh ≤ 5 singh > 5
flag2 ccratio > 0.67 0.52 < ccratio ≤ 0.67 ccratio ≤ 0.52
flag3 csi ≤ 0.55 0.55 < csi ≤ 0.65 csi > 0.65
flag4 calcar ≤ 6 6 < calcar ≤ 7 calcar > 7
So, for example, flag1 should be assigned the value 1 if singh is less than or equal to 4, flag1 should be assigned the value 2 if singh is greater than 4, but less than or equal to 5, and flag1 should be assigned the value 3 if singh is greater than 5.
In writing the necessary if-then-else statements to create the four new variables intentionally fail to program for missing values. That is, for example, your if-then-else statement for the creation of flag1 should contain just three lines — one if condition, and two else-if conditions. Similarly, the if-then-else statements for the creation of flag2, flag3, and flag4 should each contain three lines. After you've created the four flag variables, create a fifth new variable called ourscore, which is merely the sum of the four flag variables. Print the bonescore1 data set, and observe that one of the values for flag1 and one of the values for flag3 have been improperly assigned. Why? Also note that the errors in flag1 and flag3 also cause errors in the ourscore variable. Why?
b. Now, let's try to fix the errors in our last if-then-else statements. Create a new data set called bonescore2 by re-reading the data contained in Bonescor2.dat . Copy your if-then-else statements from your bonescore1 data step into your bonescore2 data step. Edit the if-then-else statements by adding an else-if condition to the end of each one that supposedly programs for missing values. For example, add:
else if singh = . then flag1 = .;
to the end of your if-then-else statements that create the flag1 variable. Make a similar mistake while attempting to program for missing values when creating each new flag variable. Print the bonescore2 data set, and observe that one of the values for flag1 and one of the values for flag3 are still improperly assigned. Why is this the case? Again note that the errors in flag1 and flag3 have been propagated to the ourscore variable.
c. Okay, let's finally get it right! Create a new data set called bonescore3 by re-reading the data contained in Bonescor2.dat . Copy your if-then-else statements from your bonescore1 data step into your bonescore3 data step. Now, edit the if-then-else statements by placing the missing value conditions in the correct locations.
After completing this assignment, you should be able to appreciate not only the critical importance of programming for missing values, but doing it correctly!

Problem 6.
In short, your assignment for this lesson involves reading the kidsbooks.txt data file into a temporary data set called kidsbooks and then generating a report.

The columns of the kidsbook.txt data file are defined as follows:
Variable Definition Columns
Title Title of the book 1-20
Author Author of the book 22-40
Publisher Publisher of the book 43-58
Pubdate Publication date 61-70
Price Price of the book 72-76
Pages Number of pages 79-80
It might not be immediately obvious but to generate the report, you'll need to select only those books whose price per page exceeds 30 cents. Another hint is that setting the page size to 38 helps to keep the footnote a nice close distance to the main content of the report. One final hint ... note that the report displays the books in descending order of price.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

Q4)
1)
Code:
data dietdata;
infile '/folders/myshortcuts/SASuni/may 2018/dietdata.dat' ;
input
Subj $1-3
Height $4-5
Wt_init 6-8
Wt_final 9-11
;
run;

data dietdata;
set dietdata;
Wt_init_kg=Wt_init/2.2;
Wt_final_kg=Wt_final/2.2;
Height_mt=(input(height, best12.))*0.0254;
bmi_init=Wt_init_kg/(Height_mt*Height_mt);
bmi_final=Wt_final_kg/(Height_mt*Height_mt);
bmi_diff=(Wt_final_kg-Wt_init_kg)/(Height_mt*Height_mt);
run;

option LINESIZE=80 pagesize=56;
Proc print data = work.dietdata;...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$88.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Applied Statistics Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats