BookmarkSubscribeRSS Feed
er_awasthi
Calcite | Level 5
Hi ,
I'm preparing for SAs certification Base exam . I have one question . Which will be more efficient between Select group and If statment. I coded this programs for practice using IF statment in one datasep and select group in another . both does same tasks but i would like to know which will be more efficeint for usage and why ? I know here I'm using test data so efficiney cant be known but still I'm curious to know which one will be better to use between select group and IF/then else statment and why ?


Program 1
DATA PATIENT;
INPUT ID $ SALARY DEPT $;
DATALINES;
1129 10000 A
1387 10000 B
2304 10000 C
4759 20000 E
5438 20000 F
6488 20000 G
9012 20000 H
;
DATA PATIENT1;
SET PATIENT;
LENGTH DEPT1 $6.;
IF DEPT IN ('A','B','C','D'') THEN DO DEPT1='ABCD';
ELSE IF DEPT IN ('F','G','H','I'')
THEN DEPT1='FGHI';
run;

DATA PATIENT2;
SET PATIENT;
LENGTH DEPT2 $6.;

SELECT (DEPT);
WHEN ('A','B','C','D') DEPT2='ABCDE';
WHEN ('F','G','H','I') DEPT2='FGHI';
OTHERWISE;
END;
Run;
Thanx
Manish
3 REPLIES 3
er_awasthi
Calcite | Level 5
Hi i tried executing multiple statments using Do loops in select statament and i got the desired reuslts.

SELECT (DEPT);
WHEN ('A','B','C','D') DO; DEPT1='ABCDE'; DEPT2='LGH'; END;
WHEN ('F','G','H','I') DEPT1='FGHIJKL';
OTHERWISE;
END;

I believe the performance of If statments and select statments and if statments depends on the data. If Program encounters True data on the top itself ( top of If and select statment ) Performance will be good but Which one to choose Between them while coding and Why ?

Thanx
Manish
LinusH
Tourmaline | Level 20
I would say that IF/SELECT are quit equal when it comes to compare performance.
There are many other things that has higher impact on performance.
But if you want to gain the best performance, I believe in IF you should put the most common true condition first. I'm not sure if this applies to SELECT as well.
Generally, I'll favor SELECT if there are more than two possible outcomes, since it is more readable.

/Linus
Data never sleeps
er_awasthi
Calcite | Level 5
Thanx..
I got it the performance depends on By putting most common condition first and this applies to both If/select statment . This works for Select statment also Thanx for clearing my doubt

Manish

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
  • 3 replies
  • 689 views
  • 0 likes
  • 2 in conversation