SAS 9.4 IF-THEN/ELSE statement problem

Solved
Frequent Contributor
Posts: 87

SAS 9.4 IF-THEN/ELSE statement problem

Hi Everyone;

I have a excel data file below:

ID type sys dia DM RF

1   b   131 86   1   0

1   a   136 89   1   0

1   c   120 80   1   0

1   d   138 70   1   0

2   b   150 90   0   0

2   a   160 89   0   0

2   c   140 90   0   0

2   d   146 91   0   0

3   b   120 78   0   1

3   a   136 81   0   1

3   c   131 80   0   1

3   d   110 70   0   1

I want to classify when DM and RF =0, if sys>=140 or dia>=90 then bp=1;

when DM=1, or RF=1, if sys>=130 or dia>=80 then bp=1;

else bp=0; I have tried different ways of

IF-THEN/ELSE Statements, but they did not work.

Thanks you so much for helping me.

Accepted Solutions
Solution
‎10-27-2014 05:35 PM
Posts: 1,270

Re: SAS 9.4 IF-THEN/ELSE statement problem

data want;

set have;

if (sys=. or dia=.) then bp=.;

else if (sys>=140 or (sys>=130 and DM=1)

or (sys>=130 and RF=1) or (dia>=90 or (dia>=80 and DM=1)) or (dia>=80 and RF=1)) then bp=0;

else bp=1;

run;

All Replies
Posts: 1,270

Re: SAS 9.4 IF-THEN/ELSE statement problem

Hi,

What final output are you expecting? Please share your syntax which you tried.

Frequent Contributor
Posts: 87

Re: SAS 9.4 IF-THEN/ELSE statement problem

HI stat@sas,

Here are my syntax:

data BP;

set BP;

if (sys=.) or (dia=.) then bp=.;

else if (sys>=140) or ((sys>=130 and (DM=1)

or (sys>=130 and RF=1)) or (dia>=90) or ((dia>=80 and DM=1) or (dia>=80 and RF=1)) then bp=0;

else bp=1;

Thanks

Solution
‎10-27-2014 05:35 PM
Posts: 1,270

Re: SAS 9.4 IF-THEN/ELSE statement problem

data want;

set have;

if (sys=. or dia=.) then bp=.;

else if (sys>=140 or (sys>=130 and DM=1)

or (sys>=130 and RF=1) or (dia>=90 or (dia>=80 and DM=1)) or (dia>=80 and RF=1)) then bp=0;

else bp=1;

run;

Frequent Contributor
Posts: 87

Re: SAS 9.4 IF-THEN/ELSE statement problem

It works pretty well. Thanks so much for your help.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 4 replies
• 505 views
• 0 likes
• 2 in conversation