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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: