Multiple conditions with multiple variables

Accepted Solution Solved
Reply
Occasional Contributor Lop
Occasional Contributor
Posts: 6
Accepted Solution

Multiple conditions with multiple variables

hello,

I'm trying to find a solution how to apply multple conditions, or another code that can help me with this condition.

My outcome is "MetSind", and I have 5 condtions. At least there should be accomplished three of them to get MetSind=yes

1. waist>88

2. tg>=150 or hyplip_treat=yes

3. hdl_c<50

4. msbp>=130 or mdbp>=85 or hta_treat=yes

5. glu>=100 or dm_dx=yes

 

I was trying to use this code: if ((waist>88) or (tg>=150 or hyplip_treat=yes) or (hdl_c<50) or (msbp>=130 or mdbp>=85 or hta_treat=yes) and (glu>=100 or dm_dx=yes)) then MetS=1 ; else MetS=0. But, clearly it doesn't work.

I am beginner sas user so I would like some expert's help.

 

Thanks for replying.

Attachment

Accepted Solutions
Solution
‎04-05-2018 04:43 AM
Super User
Posts: 10,254

Re: Multiple conditions with multiple variables

Make use of the fact that boolean values in SAS are represented as 0 and 1:

if
  (waist > 88) +
  (tg >= 150 or b6_1_3 = 2) +
  (hdl_c < 50) +
  (msbp >= 130 or mdbp >= 85 or b6_1_2 = 2) +
  (glu_0 >= 100 or dm_dx = 2)
>= 3
then MetS = 1;
else MetS = 0;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
‎04-05-2018 04:43 AM
Super User
Posts: 10,254

Re: Multiple conditions with multiple variables

Make use of the fact that boolean values in SAS are represented as 0 and 1:

if
  (waist > 88) +
  (tg >= 150 or b6_1_3 = 2) +
  (hdl_c < 50) +
  (msbp >= 130 or mdbp >= 85 or b6_1_2 = 2) +
  (glu_0 >= 100 or dm_dx = 2)
>= 3
then MetS = 1;
else MetS = 0;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor Lop
Occasional Contributor
Posts: 6

Re: Multiple conditions with multiple variables

[ Edited ]
Posted in reply to KurtBremser

Thank you so much for your valious feedback. It worked perfect.

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 159 views
  • 3 likes
  • 2 in conversation