By admin | November 18, 2009

SAS Certified Adv Programmer 130 Questions (19)

The SAS data set TEMP has the following distribution of values for variable A:

A Frequency
1 500,000
2 500,000
6 7,000,000
8 3,000

Which one of the following SAS programs requires the least CPU time to be processed?

A.

data new; 
    set temp;
    if a = 8 then
        b = ‘Small’;
    else if a in(1, 2) then
        b = ‘Medium’;
    else if a = 6 then
        b = ‘Large’;
run;

B.

data new;
    set temp;
    if a in (1, 2) then
        b = ‘Medium’;
    else if a= 8 then
        b = ‘Small’;
    else if a = 6 then
        b = ‘Large’;
run;

C.

data new;
    set temp;
    if a = 6 then 
        b = ‘Large’;
    else if a in (1, 2) then
        b = ‘Medium’;
    else if a=8 then
        b = ‘Small’;
run;

D.

data new;
    set temp;
    if a = 6 then
        b = ‘Large’;
    if a in(1, 2) then
        b = ‘Small’;
run; 

5 comments | Add One

  1. admin - 11/18/2009 at 12:15 pm

    C

  2. rob roy - 09/3/2012 at 6:36 am

    Please explain

  3. Consty - 06/6/2013 at 6:10 pm

    C. Efficient SAS programming instructs to code in descending order of frequency

  4. flyingphx - 12/19/2013 at 11:12 am

    To rob roy:
    For best performance, you always check the conditions in descending frequency order.
    You can reference page 746 on prep guide.

  5. vs - 07/19/2014 at 2:36 am

    if you are checking conditions in if statement, put the condition first in IF statement that has a chance to occur more frequently.so that we can eliminate no of further checks.

Leave a Comment

Leave a Reply

Your email address will not be published.