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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.