Computing a Character Variable in a COMPUTE Block

Reply
Contributor
Posts: 68

Computing a Character Variable in a COMPUTE Block

Hi guys, a question is seeking for your help. Thank you in advance!

Method1

define Hypertensive/ computed 'Hypertensive?' width=14;

compute Hypertensive / character length=3 ;

if Gender=F then do;

  if SBP gt 138 or DBP gt 88 then Hypertensive='Yes';

  else Hypertensive='No';

    end;

else do;

  if SBP gt 140 or DBP gt 90 then Hypertensive='Yes';

   else  Hypertensive='No';

    end;

endcomp;

run;

The result is:

Gender    SBP    DBP  Hypertensive?

  F         110     62  No

            120     70  No

            138     88  No

            132     76  No

  M         144     90  Yes

            130     80  No

            142     82  Yes

            150     96  Yes

Method2

compute Hypertensive / character length=3;

if Gender = 'F' and (SBP gt 138 or DBP gt 88)

then Hypertensive = 'Yes';

else Hypertensive='No';

if Gender = 'M' and

(SBP gt 140 or DBP gt 90)

then Hypertensive = 'Yes';

else Hypertensive = 'No';

endcomp;

run;

The result is:

Hypertensice Patients                                  

  Gender    SBP    DBP  Hypertensive?
  F         110     62  No
            120     70  No
            138     88  No
            132     76  No
  M         144     90  Yes
            130     80  No
            142     82  No
            150     96 No                                  My question is: I think the two methods will get the same result, but why it's different?

The original requirement is:

Hypertensive is defined as Yes for females if the SBP is

greater than 138 or the DBP is greater than 88 and No otherwise. For males,

Hypertensive is defined as Yes if the SBP is over 140 or the DBP is over

90 and No otherwise.

Ask a Question
Discussion stats
  • 0 replies
  • 116 views
  • 0 likes
  • 1 in conversation