************************************************************ * Program: C:\NHANES\CleanRecode_RegroupRecode.sas * * Proposal: Regroup or recode variables * ************************************************************; libname NH "C:\your_dir"; /*change the name of the directory folder to the location that you saved your downloaded dataset from the sample code and dataset downloads module: for example "c:\nhanes\data"*/ /*This program will regroup the race/ethnicity categorical variable' create an age categorical variable from an age continuous variable, define hypertension and hyperlipidemics.*/ data demo_BP3; set NH.demo_BP2b; /*Regroup race_ethnicity as 4 categories*/ if ridreth1=3 then raceth=1; /*Non-Hispanic White*/ else if ridreth1=4 then raceth=2; /*Non-Hispanic Black*/ else if ridreth1=1 then raceth=3; /*Mexican American*/ else raceth=4; /*Other*/ /*Create age categorical variable*/ if (20 <= ridageyr <= 39) then age3cat=1; else if (40 <= ridageyr <= 59) then age3cat=2; else if ridageyr >= 60 then age3cat=3; /*Count Number of Nonmissing Systolic Blood Pressure(SBP) & Diastolic Blood Pressure(DBP)*/ n_sbp = n(of bpxsy1-bpxsy4); n_dbp = n(of bpxdi1-bpxdi4); *Set DBP values of 0 as missing for calculating average; array _DBP bpxdi1-bpxdi4; do over _DBP; if (_DBP = 0) then _DBP = .; end; *Calculate mean SBP and DBP; mean_sbp = mean(of bpxsy1-bpxsy4); mean_dbp = mean(of bpxdi1-bpxdi4); /*Define hypertension based on questionnaire and exam data*/ if BPQ050a=1 then HBP_trt=1; else if BPQ020 in (1,2) and BPQ050a < 7 then HBP_trt=0; if n_sbp>0 and n_dbp>0 then do; if mean_sbp>=140 then SBP140=1; else SBP140=0; if mean_dbp>=90 then DBP90=1; else DBP90=0; end; if HBP_trt>=0 and SBP140>=0 and DBP90>=0 then do; if HBP_trt=1 or SBP140=1 or DBP90=1 then HBP=1; else HBP=0; end; /*Define high cholesterol based on questionnaire and lab data*/ if BPQ100d=1 then HLP_trt=1; else if BPQ080 in (1,2) and BPQ100d<7 then HLP_trt=0; if lbxtc>=240 then HLP_lab=1; else if lbxtc>=0 then HLP_lab=0; if HLP_lab>=0 and HLP_trt>=0 then do; if HLP_lab=1 or HLP_trt=1 then HLP=1; else HLP=0; end; run;