BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bruce123
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

3 REPLIES 3
Tom
Super User Tom
Super User

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;

CTorres
Quartz | Level 8

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,

Bruce123
Calcite | Level 5

Thank you both very much for your help.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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