Under what circumstances would you code a select construct instead Of If Statements?
That's really up to you.
For binary choices, then use ifc() or ifn() functions.
For simple if constructs with three or four branches then if statements.
For over 4 consider select.
There are no rules on this, if you prefer if statements, then use them.
Whenever I have a calculated construct that is reused in simple cases, e.g.
select(month(date3));
when(12,1,2) season="Winter";
when(3,4,5) season="Spring";
A very simple example, but with an IF statement you would have to repeat the month calculation, or insert an extra line to assign it to a variable (and one more line to drop the unneeded month variable).
It can also be a nice way to throw an error if something unexpected shows up, just omit the OTHERWISE statement.
@rinugour wrote:
Under what circumstances would you code a select construct instead Of If Statements?
As soon as it makes the code more readable. If in doubt, put both versions side-by-side and see which one looks better to you.
A potential performance gain has to be determined through testing (in most cases, there won't be a noticeable difference).
The select statement is used when you are using one condition to compare with several conditions like.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.