-
Notifications
You must be signed in to change notification settings - Fork 0
/
PH490KR_Session16
126 lines (98 loc) · 2.98 KB
/
PH490KR_Session16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/********************************
THIS PROGRAM COMPLETES ACTIVITY FOR
SESSION 16, PH490KR SPRING 2018
EMILY LYNCH
MARCH 23, 2018
*********************************/
libname ph490kr "C:\Users\emilylynch\Desktop\ph490kr";
data sess16; /*read in data into a temporary dataset that is stored in work and called sess16*/
set ph490kr.vitdsess16; /*this is the dataset being read in*/
*1. create a new variable coding as never, past, or current smokers;
*first, we will look at ev_smk & cur_smk in a table, see *A*. below;
if cur_smk=1 then smoke=2; /*current smokers*/
else if ev_smk=1 & cur_smk=0 then smoke=1; /*past smokers*/
else if ev_smk=0 then smoke=0;
*now check our work, see *B* below;
*2. dichtomize weight at the median, first need to find the median, see *C* below;
if wt_lbs<=136 then wt_med=1;
else if wt_lbs>136 then wt_med=2;
if wt_lbs=. then wt_med=.;
*check our work, see *D* below;
*3. create a new variable calculating BMI;
bmi=wt_lbs/(ht_in*ht_in)*703;
*check our work, see *E* below;
*4. group bmi into who categories;
if (bmi<18.5) then bmicat=1;
else if (bmi>=18.5) & (bmi<25) then bmicat=2;
else if (bmi>=25) & (bmi<30) then bmicat=3;
else if (bmi>=30) then bmicat=4;
else if bmi=. then bmicat=.;
*check our work, see *F* below;
*5. convert height to meters;
ht_m=ht_in*.0254;
*check our work, see *G* below;
run;
*6. save as a permanent SAS dataset;
data ph490kr.vitdsess16_ECL;
set sess16;
run;
*A*. look at cross-tabulation of ev_smk and cur_smk;
proc freq data=sess16;
table ev_smk*cur_smk /missing;
run;
*B* check our work for creating smoke;
proc freq data=sess16;
table smoke;
run;
proc print data=sess16 (obs=100);
var ev_smk cur_smk smoke;
run;
*C* find the median value of weight;
proc univariate data=sess16;
var wt_lbs;
run;
/*median wt_lbs=136.00*/
*D* check our work in dichotomizing weight;
proc print data=sess16 (obs=50);
var wt_lbs wt_med;
run;
proc sort data=sess16;
by wt_med;
run;
proc univariate data=sess16;
by wt_med;
var wt_lbs;
run;
*E* check work in creating bmi;
proc print data=sess16 (obs=50);
var wt_lbs ht_in bmi;
run;
proc univariate data=sess16;
var bmi;
run;
*F* check work in categorizing BMI;
proc print data=sess16 (obs=75);
var bmi bmicat;
run;
*G* check work in converting height to meters;
proc print data=sess16 (obs=25);
var ht_m ht_in;
run;
***EXTRA: LABEL VARIABLES AND THEIR VALUES***;
proc format library=ph490kr;
value smokef 0="0_never" 1="1_past" 2="2_current";
value wt_medf 1="1:weight <=136 lbs" 2="2:weight >136 lbs";
value bmicatf 1="1_underweight" 2="2_normal weight" 3="3_overweight" 4="4_obese";
run;
options fmtsearch=(ph490kr);
data ph490kr.vitdsess16_ECL; /*note, this code will overwrite my permanent SAS dataset*/
set ph490kr.vitdsess16_ECL;
format smoke smokef. wt_med wt_medf. bmicat bmicatf.;
label smoke="smoke: smoking status";
label wt_med="wt_med: weight relative to median";
label bmi="bmi: BMI, kg/m2";
label bmicat="bmicat: BMI category";
label ht_m="ht_m: height in meters";
run;
proc contents data=ph490kr.vitdsess16_ECL;
run;