Hello team,
I want to write two nested case statements:
case1
field1 > field2 and field2> field3 and field3 >field4 then
case1
case2
case3
case2 field1 < field2 and field2< field3 and field3 <field4 then
case1
case2
case3
What would be the syntax? Or is this doable?
Regards,
Blue blue
I don't really understand what you are trying to do.
Can you explain in words? Can you give a small example?
If field1 > field2 then
When case ….then,,,
When case….then…
End as ‘this’Else
When case.,,,then….
When case….then.,.End as ‘that’
End if
I still don't understand the question.
Hello,
Please refer to this:
You're trying to check if the fields are sorted in order of ascending or descending?
Yes, I am trying to see how I need to write it.
Regards,
blue blue
Hello all,
yes, I need to nest my case statement within another case statement of within an if else statement:
but I have to say if the sort is like field1 > field 2, then
else somethingelse
end;
But within each part of if else we have case statements.
I hope this makes sense.
Thanks,
blueblue
Reeza,
Thanks for the response.
This is the sketch of what I have in mind.
case
When (field1>field2 and field2>field3) Then
case
when this then than /*this is nested within the first case*/
when this then than /*this is nested within the first case*/
end
When (field1<field2 and field2<field3) Then
case
when this then than /*this is nested within the first case*/
when this then than /*this is nested within the first case*/
end
end
Thanks for the response.
blueblue
Yes, I am trying to nest two case statement.
Regards,
blueblue
Entirely useless example:
proc sql;
create table example as
select *, case when age <14 then (case when sex = 'F' then "FEMALE" else "MALE" end)
when age >=14 then (case when sex = 'F' then "Female" else "Male" end) end as gender
from sashelp.class;
quit;
Please give me some time to test it.
Regards,
blueblue
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.