DATA Step, Macro, Functions and more

Explanation of Select processing vs. if-then processing

Reply
N/A
Posts: 0

Explanation of Select processing vs. if-then processing

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!
Super User
Posts: 5,441

Re: Explanation of Select processing vs. if-then processing

Posted in reply to deleted_user
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
Occasional Contributor
Posts: 16

Re: Explanation of Select processing vs. if-then processing

Posted in reply to deleted_user
Check this thread posted by me.

http://support.sas.com/forums/thread.jspa?threadID=7030


Thanks
Manish
Ask a Question
Discussion stats
  • 2 replies
  • 126 views
  • 0 likes
  • 3 in conversation