Conflicting indicator variable code

Accepted Solution Solved
Reply
Contributor
Posts: 47
Accepted Solution

Conflicting indicator variable code

Hello

I have a small code for creating a indicator variable. But the code is conflicting with each other and so one of the statements is not been read by SAS, and I do not know of another way to write it.

My code can be seen below:

Data want;

Length Colour $6;

Set Have;

If Performance_2014 <0 And Performance_2013 <0 And Performance_2012 <0 And Performance_2011 <0 then indikator = 1;

Else indikator = 3;

If Performance_2014 <0 And Performance_2013 <0 And Performance_2012 <0 then indikator = 2;

run;

If all 4 years are negative, the indicator still gives the value "2" because of the second statement, even though it should give "1", .

Is there anyway to ask SAS to first check if all 4 years have a negative value and if this is not true, then check if the last 3 years are negative?

I managed to get this to work in excel, but not in SAS. In excel it would look like this:

If(and(C2<0;D2<0;E2<0;F2<0);"0";If(and(D2<0;E2<0;F2<0);"1";"3"))

Thank you for your time and help


Accepted Solutions
Solution
‎01-09-2014 10:20 AM
Super User
Super User
Posts: 6,502

Re: Conflicting indicator variable code

Just make sure to use proper IF/THEN/ELSE nesting.

If Performance_2014 <0 And Performance_2013 <0 And Performance_2012 <0 And Performance_2011 <0 then indikator = 1;

ELSE If Performance_2014 <0 And Performance_2013 <0 And Performance_2012 <0 then indikator = 2;

Else indikator = 3;

View solution in original post


All Replies
Solution
‎01-09-2014 10:20 AM
Super User
Super User
Posts: 6,502

Re: Conflicting indicator variable code

Just make sure to use proper IF/THEN/ELSE nesting.

If Performance_2014 <0 And Performance_2013 <0 And Performance_2012 <0 And Performance_2011 <0 then indikator = 1;

ELSE If Performance_2014 <0 And Performance_2013 <0 And Performance_2012 <0 then indikator = 2;

Else indikator = 3;

Regular Contributor
Posts: 180

Re: Conflicting indicator variable code

Try this:

If Performance_2014 <0 And Performance_2013 <0 And Performance_2012 <0 And Performance_2011 <0 then indikator = 1;

Else If Performance_2014 <0 And Performance_2013 <0 And Performance_2012 <0 then indikator = 2;

Else indikator = 3;

You could also try the IFN Function.

Regards,

Contributor
Posts: 47

Re: Conflicting indicator variable code

Thank you both very much for your help.

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 175 views
  • 3 likes
  • 3 in conversation