Interesting article, Rick!

I have tried to do the same with SELECT-WHEN statement considering almost all of the discussion points mentioned in the article.

- Does the implementation handle missing values (.) ?
- Does the program correctly handle negative integers? What about 0?
- What does the program do if the input data are not integers? For example, what is FizzBuzz(3.2)?
- How would you modify the program to detect whether the input is not a positive integer and write "Jazz" in that case?
- Suppose the input data set contains one billion observations. Discuss the efficiency of your implementation of FizzBuzz.

I have compared output of SELECT-WHEN code (referring to my below code) and proc fcmp - FizzBuzz function - An intermediate SAS programmer writes the FizzBuzz program (referring to the code mentioned above in the article) but with 100000000 observations.

Time taken by using FizzBuzz function with proc fcmp:
real time 36.15 seconds

Time taken by using SELECT-WHEN:
real time 21.39 seconds

We can say that SELECT-WHEN is faster than IF-ELSE as well as SAS Function used in data step..
Here is the code with SELECT-WHEN Statement:

data Have;
do n=0 to 100000000;
output;
end;
n=-1; output;
n=-5; output;
n=.; output;
n=1.5; output;
n=-1.5; output;
run;

data Want;
set Have;
length Word $8;
select (n ne 0.9999);
when (n<=0 OR (abs(n)-int(n)) ne 0) Word="Jazz"; /* handle if n is not +ve integer (ex. 0, ., -2, -1.5, 1.5) */
when (mod(n,15)=0) Word = "FizzBuzz";
when (mod(n,5)=0) Word = "Buzz";
when (mod(n,3)=0) Word = "Fizz";
otherwise Word = left(put(n, 8.));
end;
run;