******************************************************************************************************************; * Example SAS code to replicate NCHS Data Brief No. 405, Figures 1 & 2 *; *; * Osteoporosis of Low Bone Mass in Older Adults:United States, 2017-2018 *; * *; * Sarafrazi N, Wambogo EA, Shephered JA. Osteoporosis of Low Bone Mass in Older Adults:United States, 2017-2018 *; * NCHS Data Brief. No 405. Hyattsville, MD: National Center for Health Statistics. 2021. *; * *; * Available at: https://www.cdc.gov/nchs/products/databriefs/db405.htm *; ******************************************************************************************************************; options nocenter nodate nonumber pagesize=100 linesize=150; OPTIONS FORMCHAR="|----|+|---+=|-/\<>*"; %put Run in SAS &sysver (maintenance release and release year: &sysvlong4); ** Macro To Download Data from NHANES website **; %macro CreateDS(myDS); %let i = 1; %let DS = %scan(&myDS, &i); %do %until(&DS = %nrstr()); %let Suffix = %lowcase(%substr(&DS, %eval(%length(&DS)-1))); %if (&Suffix = _j) %then %do; filename &DS url "https://wwwn.cdc.gov/nchs/nhanes/2017-2018/&DS..xpt"; %end; %else %if (&Suffix = _i) %then %do; filename &DS url "https://wwwn.cdc.gov/nchs/nhanes/2015-2016/&DS..xpt"; %end; %else %if (&Suffix = _h) %then %do; filename &DS url "https://wwwn.cdc.gov/nchs/nhanes/2013-2014/&DS..xpt"; %end; %else %if (&Suffix = _g) %then %do; filename &DS url "https://wwwn.cdc.gov/nchs/nhanes/2011-2012/&DS..xpt"; %end; %else %if (&Suffix = _f) %then %do; filename &DS url "https://wwwn.cdc.gov/nchs/nhanes/2009-2010/&DS..xpt"; %end; %else %if (&Suffix = _e) %then %do; filename &DS url "https://wwwn.cdc.gov/nchs/nhanes/2007-2008/&DS..xpt"; %end; %else %if (&Suffix = _d) %then %do; filename &DS url "https://wwwn.cdc.gov/nchs/nhanes/2005-2006/&DS..xpt"; %end; %else %if (&Suffix = _c) %then %do; filename &DS url "https://wwwn.cdc.gov/nchs/nhanes/2003-2004/&DS..xpt"; %end; %else %if (&Suffix = _b) %then %do; filename &DS url "https://wwwn.cdc.gov/nchs/nhanes/2001-2002/&DS..xpt"; %end; %else %do; filename &DS url "https://wwwn.cdc.gov/nchs/nhanes/1999-2000/&DS..xpt"; %end; libname &DS xport; data &DS; set &DS..&DS; run; %let i = %eval(&i+1); %let DS = %scan(&myDS, &i); %end; %mend CreateDS; ** HOW TO USE **; %CreateDS( demo_d demo_e demo_f demo_g demo_h demo_i demo_j DXX_I DXX_j DXXFEM_J DXXSPN_J DXXFEM_D DXXSPN_D DXXFEM_E DXXSPN_E DXXFEM_F DXXSPN_F DXXSPN_H DXXFEM_H); data DXXFEM; set DXXFEM_D DXXFEM_E DXXFEM_F DXXFEM_H DXXFEM_J;run; data DXXSPN; set DXXSPN_D DXXSPN_E DXXSPN_F DXXSPN_H DXXSPN_J;run; data DEMO; set demo_D demo_E demo_F demo_H demo_j;run; PROC SORT DATA=dxxspn;by seqn;run; PROC SORT DATA=dxxfem;by seqn;run; PROC SORT DATA=demo;by seqn;run; data dexa; merge DEMO(keep=seqn riagendr ridageyr ridreth1 RIDRETH3 ridexprg sdmvstra sdmvpsu wtmec2yr sddsrvyr) DXXSPN(keep=seqn DXXL1BCC DXXL2BCC DXXL3BCC DXXL4BCC DXXOSBMD DXXL1BMD DXXL2BMD DXXL3BMD DXXL4BMD) DXXFEM(keep=seqn DXXNKBMD); by seqn; run; proc format; value sexfmt 1="Males" 2="Females" 0="All"; value agecatfmt 0='ALL' 1="50-64" 2="65+"; VALUE racefmt 0 = 'ALL' 1 = 'NHW' 2 = 'NHB' 3 = 'Hispanic' 4 = 'Asian' 5 = 'Other'; value race2fmt 0='All race/ethnic groups' 1='NHW' 2='NHB' 3='HISPANIC' 4='Other, inc Asian'; VALUE race3fmt 0 = 'ALL' 1 = 'NHW' 2 = 'NHB' 3 = 'Hispanic' 4 = 'Asian' 5 = 'Other'; value kcyc6fmt 0='ALL' 1='NHANES 2005-2006' 2='NHANES 2007-2008' 3='NHANES 2009-2010' 4='NHANES 2013-2014' 5='NHANES 2017-2018'; value femurfmt 0 ='ALL' 1 ='Osteoporosis' 2 ='Low_bone_mass' 3 ='Normal'; value spnstatfmt 0 ='ALL' 1 ='Osteoporosis_spine' 2 ='LBM_spine' 3 ='Normal_spine'; value femstatfmt 0 ='ALL' 1 ='Osteoporosis_femur' 2 ='LBM_femur' 3 ='Normal_femur'; value bonstatfmt 0 ='ALL' 1 ='Osteoporosis_either_site' 2 ='LBM_both_or_either_site' 3 ='Normal_both_sites'; run; data DEXA2; set DEXA; /*SAS code to calculate femoral neck T-Score, Lumbar spine BMD and Lumbar spine T-score Selected variables of interest to create: DXXNKBMD - Femoral neck BMD DXXL1BCC - L1 BMD invalidity code DXXL2BCC - L2 BMD invalidity code DXXL3BCC - L3 BMD invalidity code DXXL4BCC - L4 BMD invalidity code DXXOSBMD - Total spine BMD DXXL1BMD - L1 BMD DXXL2BMD - L2 BMD DXXL3BMD - L3 BMD DXXL4BMD - L4 BMD*/ /*1. FN_T:*/ fn_t= (dxxnkbmd - 0.86)/0.12; /*Total_femur_T_score= (dxxofbmd - 0.94)/0.122; */ /*2. LSBMD and LS_T*/ *create counting variable for invalid vertebra; if dxxl1bcc gt 0 then invalid_l1=1; if dxxl1bcc eq 0 then invalid_l1=0; if dxxl2bcc gt 0 then invalid_l2=1; if dxxl2bcc eq 0 then invalid_l2=0; if dxxl3bcc gt 0 then invalid_l3=1; if dxxl3bcc eq 0 then invalid_l3=0; if dxxl4bcc gt 0 then invalid_l4=1; if dxxl4bcc eq 0 then invalid_l4=0; invalid_sum = invalid_l1 + invalid_l2 + invalid_l3 + invalid_l4; *Calculate spine t scores using Hologic white female AP spine reference data; ****AFTER RECALCULATING TOTAL SPINE BMD TO ALLOW FOR 4 VALID VERT!!!!!!!!; *l1,2,3,4; if invalid_sum eq 0 then LS_T = (dxxosbmd - 1.047)/0.11; if invalid_sum eq 0 then LSBMD=DXXOSBMD; *L2,3,4; if invalid_sum eq 1 and invalid_l1 eq 1 THEN TOTSPINEBMD_234=(dxxl2bmd + dxxl3bmd + dxxl4bmd)/3; if invalid_sum eq 1 and invalid_l1 eq 1 then LS_T = (totspinebmd_234 - 1.079)/0.11; if invalid_sum eq 1 and invalid_l1 eq 1 THEN LSBMD= TOTSPINEBMD_234; *L1,3,4; if invalid_sum eq 1 and invalid_l2 eq 1 THEN TOTSPINEBMD_134=(dxxl1bmd + dxxl3bmd + dxxl4bmd)/3; if invalid_sum eq 1 and invalid_l2 eq 1 THEN LS_T = (totspinebmd_134 - 1.053)/0.11; if invalid_sum eq 1 and invalid_l2 eq 1 THEN LSBMD=TOTSPINEBMD_134; *L1,2,4; if invalid_sum eq 1 and invalid_l3 eq 1 THEN TOTSPINEBMD_124=(dxxl1bmd + dxxl2bmd + dxxl4bmd)/3; if invalid_sum eq 1 and invalid_l3 eq 1 then LS_T = (totspinebmd_124 - 1.034)/0.11; if invalid_sum eq 1 and invalid_l3 eq 1 THEN LSBMD=TOTSPINEBMD_124; *L1,2,3; if invalid_sum eq 1 and invalid_l4 eq 1 THEN TOTSPINEBMD_123=(dxxl1bmd + dxxl2bmd + dxxl3bmd)/3; if invalid_sum eq 1 and invalid_l4 eq 1 then LS_T = (totspinebmd_123 - 1.018)/0.11; if invalid_sum eq 1 and invalid_l4 eq 1 THEN LSBMD=TOTSPINEBMD_123; *L3,4; if invalid_sum eq 2 and invalid_l1 eq 1 and invalid_l2 eq 1 THEN TOTSPINEBMD_34=(dxxl3bmd + dxxl4bmd )/2; if invalid_sum eq 2 and invalid_l1 eq 1 and invalid_l2 eq 1 then LS_T = (totspinebmd_34 - 1.101)/0.11; if invalid_sum eq 2 and invalid_l1 eq 1 and invalid_l2 eq 1 THEN LSBMD=TOTSPINEBMD_34; *L2,4; if invalid_sum eq 2 and invalid_l1 eq 1 and invalid_l3 eq 1 THEN TOTSPINEBMD_24=(dxxl2bmd + dxxl4bmd)/2; if invalid_sum eq 2 and invalid_l1 eq 1 and invalid_l3 eq 1 then LS_T = (totspinebmd_24 - 1.077)/0.11; if invalid_sum eq 2 and invalid_l1 eq 1 and invalid_l3 eq 1 THEN LSBMD=TOTSPINEBMD_24; *L2,3; if invalid_sum eq 2 and invalid_l1 eq 1 and invalid_l4 eq 1 THEN TOTSPINEBMD_23=(dxxl2bmd + dxxl3bmd)/2; if invalid_sum eq 2 and invalid_l1 eq 1 and invalid_l4 eq 1 then LS_T = (totspinebmd_23 - 1.058)/0.11; if invalid_sum eq 2 and invalid_l1 eq 1 and invalid_l4 eq 1 THEN LSBMD=TOTSPINEBMD_23; *L1,4; if invalid_sum eq 2 and invalid_l2 eq 1 and invalid_l3 eq 1 THEN TOTSPINEBMD_14=(dxxl1bmd + dxxl4bmd)/2; if invalid_sum eq 2 and invalid_l2 eq 1 and invalid_l3 eq 1 then LS_T =(totspinebmd_14 - 1.037)/0.11; if invalid_sum eq 2 and invalid_l2 eq 1 and invalid_l3 eq 1 THEN LSBMD=TOTSPINEBMD_14; *L1,3; if invalid_sum eq 2 and invalid_l2 eq 1 and invalid_l4 eq 1 THEN TOTSPINEBMD_13=(dxxl1bmd + dxxl3bmd)/2; if invalid_sum eq 2 and invalid_l2 eq 1 and invalid_l4 eq 1 then LS_T = (totspinebmd_13 - 1.013)/0.11; if invalid_sum eq 2 and invalid_l2 eq 1 and invalid_l4 eq 1 THEN LSBMD=TOTSPINEBMD_13; *L1,2; if invalid_sum eq 2 and invalid_l3 eq 1 and invalid_l4 eq 1 THEN TOTSPINEBMD_12=(dxxl1bmd + dxxl2bmd)/2; if invalid_sum eq 2 and invalid_l3 eq 1 and invalid_l4 eq 1 then LS_T = (totspinebmd_12 - 0.979)/0.11; if invalid_sum eq 2 and invalid_l3 eq 1 and invalid_l4 eq 1 THEN LSBMD=TOTSPINEBMD_12; if ridageyr GE 50 and dxxnkbmd >. or (invalid_sum ne . and invalid_sum le 2) then selb=1; else selb=0; /*Create variables to define skeletal status at the femur neck or lumbar spine*/ /*Create a 3-category variable for femur neck status:*/ /*NOTE: If FN_T eq . then femur neck status variable = .;*/ /*femstat=1 (osteoporosis) femstat=2 (low bone mass) femstat=3 (normal)*/ if FN_T le -2.5 then femstat= 1; if FN_T gt -2.5 and FN_T lt -1.0 then femstat= 2; if FN_T ge -1.0 then femstat= 3; if FN_T eq . then femstat=.; /*Create a 3-category variable for lumbar spine status*/ /*NOTE: if LS_T = . then lumbar spine status variable should = .;*/ /*spnstat=1 (osteoporosis) spnstat=2 (low bone mass) spnstat=3 (normal)*/ if LS_T le -2.5 then spnstat = 1; if LS_T gt -2.5 and LS_T lt -1.0 then spnstat= 2; if LS_T ge -1.0 then spnstat= 3; if LS_T = . then spnstat=.; /*Create a 3-category variable to combine the femur neck and lumbar spine status variables */ /*NOTE: This analysis should be limited to respondents with non-missing data for femur neck status and lumbar spine status */ /*Category 1: Osteoporosis at EITHER femur neck or lumbar spine: */ /*Category 2: Low bone mass at both skeletal sites OR low bone mass at one site, normal at other site: */ /*NOTE: we do not want to count someone with osteoporosis at one site and low bone mass at the other site in this category*/ /*Category 3: Normal at both skeletal sites:*/ if femstat= 1 or spnstat= 1 then bonstat=1;/*osteo_either_sites*/ if (femstat= 2 and spnstat= 2) OR (femstat= 2 and spnstat=3) OR (femstat= 3 and spnstat= 2) then bonstat=2;/*LBM either site*/ if femstat= 3 and spnstat= 3 then bonstat=3;/*Normal both site*/ ***Construct sample MEC weight for the 5 cycles; if sddsrvyr in (4,5,6,8,10) then wtmec2yr2= wtmec2yr*1/5; /* for 2005-2018 */ if sddsrvyr=4 then kcyc6=1; if sddsrvyr=5 then kcyc6=2; if sddsrvyr=6 then kcyc6=3; if sddsrvyr=8 then kcyc6=4; if sddsrvyr=10 then kcyc6=5; agecat=.; if 50<=ridageyr le 64 then ageCat=1; if ridageyr ge 65 then ageCat=2; sex=riagendr; *RACE; * recode race/ethnicity; race=.; if RIDRETH3=3 then race=1; *Non-Hispanic White; if RIDRETH3=4 then race=2; *Non-Hispanic Black; if RIDRETH3 in (1,2) then race=3; *HISPANIC**********; if RIDRETH3=6 then race=4; *Asian*************; if RIDRETH3=7 then race=5; *Other*************; race2=.; if RIDRETH1=3 then race2=1; *Non-Hispanic White; if RIDRETH1=4 then race2=2; *Non-Hispanic Black; if RIDRETH1 in (1,2) then race2=3; *HISPANIC**********; if RIDRETH1 in (5) then race2=4; *Other, including Asian*************; race3=.; if RIDRETH1=3 then race3=1; *Non-Hispanic White; if RIDRETH1=4 then race3=2; *Non-Hispanic Black; if RIDRETH1 in (1,2) then race3=3; *HISPANIC**********; if RIDRETH3 in (6) then race3=4; * Asian*************; if RIDRETH3=7 then race3=5; *Other*************; LABEL ageCat = 'AGE GROUP' race = 'Race ethnicity' riagendr = 'Gender' ; format agecat agecatfmt. sex sexfmt. race racefmt. race2 race2fmt. race3 race3fmt. bonstat bonstatfmt. spnstat spnstatfmt. femstat femstatfmt. kcyc6 kcyc6fmt. ; RUN; ****************************************************************; *Subset 2017-2018 data*; ****************************************************************; data Dexa3;set Dexa2; where kcyc6=5; run; *****************************************************************; *PROPORTIONS**; *****************************************************************; proc surveyfreq data=Dexa3 ; * specify survey design variables in the strata, cluster, and weight statements *; strata SDMVSTRA; cluster SDMVPSU; weight wtmec2yr; * specify analysis variable(s) in the table statement *; table agecat*sex*bonstat/row col wchisq wllchisq nostd chisq chisq1; * specify subpopulation(s) of interest in the domain statement *; where selb=1; format sex sexfmt. agecat agecatfmt. bonstat bonstatfmt.; run ;