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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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