In: Math
I need the code in SAS and R and outputs please
2. The data below come from a study investigating a method of measuring body composition, and give the body fat percentage (% fat), age and sex for 18 adults aged between 23 and 61 years. Source: Mazess, R.B., Peppler, W.W., and Gibbons, M. (1984) Total body composition by dual-photon (153GD) absorptiometry. American Journal of Clinical Nutrition, 40, 834-839.
age | % fat | sex |
23 | 9.5 | male |
23 | 27.9 | female |
27 | 7.8 | male |
27 | 17.8 | male |
39 | 31.4 | female |
41 | 25.9 | female |
45 | 27.4 | male |
49 | 25.2 | female |
50 | 31.1 | female |
53 | 34.7 | female |
53 | 42.0 | female |
54 | 29.1 | female |
56 | 32.5 | female |
57 | 30.3 | female |
58 | 33.0 | female |
58 | 33.8 | female |
60 | 41.1 | female |
61 | 34.5 | female |
a Enter the data into SAS using a DATALINES statement in the DATA step. Use PROC PRINT to print the resulting data set. Report your output.
b Create a data frame in R for the body composition data (from part a). Print the data frame and report the output.
(a) SAS code:
data mydata;
input age fat sex$;
datalines;
23 9.5 male
23 27.9 female
27 7.8 male
27 17.8 male
39 31.4 female
41 25.9 female
45 27.4 male
49 25.2 female
50 31.1 female
53 34.7 female
53 42.0 female
54 29.1 female
56 32.5 female
57 30.3 female
58 33.0 female
58 33.8 female
60 41.1 female
61 34.5 female
;
run;
proc print data=mydata;
run;
SAS-OUTPUT:
Obs | age | fat | sex |
---|---|---|---|
1 | 23 | 9.5 | male |
2 | 23 | 27.9 | female |
3 | 27 | 7.8 | male |
4 | 27 | 17.8 | male |
5 | 39 | 31.4 | female |
6 | 41 | 25.9 | female |
7 | 45 | 27.4 | male |
8 | 49 | 25.2 | female |
9 | 50 | 31.1 | female |
10 | 53 | 34.7 | female |
11 | 53 | 42.0 | female |
12 | 54 | 29.1 | female |
13 | 56 | 32.5 | female |
14 | 57 | 30.3 | female |
15 | 58 | 33.0 | female |
16 | 58 | 33.8 | female |
17 | 60 | 41.1 | female |
18 | 61 | 34.5 | female |
(b) R-code:
data.frame(age=c(23,23,27,27,39,41,45,49,50,53,53,54,56,57,58,58,60,61),fat=c(9.5,27.9,7.8,17.8,31.4,25.9,27.4,25.2,31.1,34.7,42.0,29.1,32.5,30.3,33.0,33.8,41.1,34.5),sex=c("male","female","male","male","female","female","male","female","female","female","female","female","female","female","female","female","female","female"))
R-OUTPUT:
1 23 9.5 male
2 23 27.9 female
3 27 7.8 male
4 27 17.8 male
5 39 31.4 female
6 41 25.9 female
7 45 27.4 male
8 49 25.2 female
9 50 31.1 female
10 53 34.7 female
11 53 42.0 female
12 54 29.1 female
13 56 32.5 female
14 57 30.3 female
15 58 33.0 female
16 58 33.8 female
17 60 41.1 female
18 61 34.5 female