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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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
  • 1282 views
  • 0 likes
  • 3 in conversation