************************************************************ * Program: C:\NHANES\CleanRecode_RecodeSkip * * Proposal: Code variable based on skip pattern * ************************************************************; 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"*/ /*Recode blood pressure variable based on skip pattern and create derived variable based on skip pattern*/ /*Recode option 1: Directly recode variable and check recoding*/ Data demo_BP2a; set NH.demo_BP1; If BPQ030=1 then BPQ030=1; Else if BPQ020 in (1,2) and BPQ030 <7 then BPQ030=2; Else BPQ030=.; Proc freq data=demo_BP2a; where ridstatr=2 and ridageyr>=20; table BPQ020*BPQ030/list missing; title 'Check recode BPQ030'; run; /*Recode option 2: Create derived variable (diagHTN) 1-yes, 2-No*/ Data demo_BP2b; set NH.demo_BP1; If BPQ030=1 then diagHTN=1; Else if BPQ020 in (1,2) and BPQ030 <7 then diagHTN=2; Proc freq data=demo_BP2b; where ridstatr=2 and ridageyr>=20;* interviewed and examined(ridstatr=2), adults age 20+; table diagHTN*BPQ020*BPQ030/list missing; title 'Check derived variable diagHTN'; run;