- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I don't really understand what you are trying to do.
Can you explain in words? Can you give a small example?
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So would that be;
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
Regards.
Blueblue
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think it's time you illustrate your problem with some example data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks,
blueblue
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes, I am trying to nest two case statement.
Regards,
blueblue
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please give me some time to test it.
Regards,
blueblue