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
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;
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;
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,
Thank you both very much for your help.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.