culturalmonth
culturalmonth

Reputation: 13

SAS coding help displaying all created variables

I am trying to distinguish recorded subjects who have confirmed hypertension, unaware of their status, and do not have hypertension. My current code only displays bpstatus 1&2 but i missing bpstatus 3 to show up. HTN= (1=hypertension) (0=no hypertension)... HAE(1=Aware of Hypertension) (2=unaware of Hypertension)

data new
set mergedata;
HTN=.;
If SBP >= 140 or DBP >= 90 then  HTN = 1;
else if 0 < SBP < 140 and 0 < DBP < 90 then HTN = 0;
run;
proc print data=new;
    run;
data new2;
set new;
BPSTATUS=.;
*3-level variable BPSTASTUS;
*diagnosed first;
if HTN=1 or HAE2=1 then BPSTATUS=1;
*undiagnosed;
if HTN=1 and HAE2=2 then BPSTATUS=2;
*normal;
if HTN=2 and HAE2=2 then BPSTATUS=3;
run;
proc print data=new2;
    run;
proc freq data=new2;
table bpstatus;
run;
---------
BPSTATUS  
          Freq         %          Cum Freq    Cum %
1        2354         67.76        2354         67.76 
2        1120        32.24         3474         100.00 
Frequency Missing = 4424 

Upvotes: 1

Views: 33

Answers (1)

Stu Sztukowski
Stu Sztukowski

Reputation: 12909

In this code:

data new
    set mergedata;
    HTN=.;
    If SBP >= 140 or DBP >= 90 then  HTN = 1;
    else if 0 < SBP < 140 and 0 < DBP < 90 then HTN = 0;
run;

You initialize HTN to be missing, then set it to either 1 or 0 based on some conditions. In subsequent code, you check for this:

if HTN=2 and HAE2=2 then BPSTATUS=3;

Based on the logic in your first program, HTN will never be 2, which means BPSTATUS will never be 3.

Upvotes: 1

Related Questions