BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi everyone.

I am working on a presentation of the Select statement vs. if-then/else conditional logic, and I am trying to find a paper or explanation of how SAS processes if-then logic differently than the select statement. If anyone knows of a good SUGI paper or another explanation online, that would be great.

Otherwise, here's the gist of what I'm comparing.

Compare these two examples.

data one;
set old;
select (var);
when (1) flag = 1;
when (2) flag = 2;
otherwise flag = 3;
end; * end select;
run;

data two;
set old;
if var = 1 then flag = 1;
else if var = 2 then flag = 2;
else flag = 3;
run;

My understanding of the second example is that SAS will process line by line, checking first if var = 1, then cycling to the top and looking for var = 2, then setting setting flag = 3 for all other lines.

I have read from SAS that the select statement can be faster than if-then/else logic, so I'm wondering if anyone can explain how SAS processes the select statement differently than using if-then logic.

Thanks!
2 REPLIES 2
LinusH
Tourmaline | Level 20
I can't that this is an issue any more. Maybe for 10-15 ago, with slower CPU's.
Select is easier to code (and maintain), if-then-else offers more flexibility.

/Linus
Data never sleeps

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1429 views
  • 0 likes
  • 3 in conversation