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 ?
INPUT ID $ SALARY DEPT $;
1129 10000 A
1387 10000 B
2304 10000 C
4759 20000 E
5438 20000 F
6488 20000 G
9012 20000 H
LENGTH DEPT1 $6.;
IF DEPT IN ('A','B','C','D'') THEN DO DEPT1='ABCD';
ELSE IF DEPT IN ('F','G','H','I'')
LENGTH DEPT2 $6.;
WHEN ('A','B','C','D') DEPT2='ABCDE';
WHEN ('F','G','H','I') DEPT2='FGHI';
Hi i tried executing multiple statments using Do loops in select statament and i got the desired reuslts.
WHEN ('A','B','C','D') DO; DEPT1='ABCDE'; DEPT2='LGH'; END;
WHEN ('F','G','H','I') DEPT1='FGHIJKL';
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 ?
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.