By admin | November 25, 2009

SAS Certified Adv Programmer 130 Questions (23)

The SAS data set ONE consists of five million observations and has 25 variables.

Which one of the following SAS programs successfully creates three new variables TOTREV, TOTCOST, and PROFIT and requires the least CPU time to be processed?

A.

data two;
    set one;
    totrev sum(price * quantity);
    totcost = sum(fixed,variable);
    profit = sum(totrev,totcost); 
    if totrev> 1000; 
run;

B.

data two;
    set one;
    totrev = sum(price * quantity);
    if totrev> 1000;
        totcost = sum(fixed,variable);
    profit = sum(totrev,totcost); 
run;

C.

data two;
    set one; 
    totrev = sum(price * quantity);
    where totrev> 1000;
    totcost = sum(fixed,variable);
    profit = sum(totrev,totcost);
run;

D.

data two;
    set one; where totrev> 1000;
    totrev = sum(price * quantity);
    totcost = sum(fixed,variable);
    profit = sum(totrev,totcost);
run; 

4 comments | Add One

  1. admin - 11/25/2009 at 11:33 am

    B

  2. Consty - 02/19/2013 at 3:16 pm

    B. the two last variables are created on condition the first computed fullfilled certain number of conditions

  3. new user - 04/1/2013 at 11:07 am

    Could admin please explain why is B instead of C since my understanding is if statement evaluate all the data and then pick the right one, instead where only picks up the right one and therefore is more efficient.

  4. chinawokee - 07/9/2014 at 9:59 pm

    I may not be correct!
    But I feel if you use where, you are still dealing with the old dataset instead of the new one in the following two steps…

Leave a Comment

Leave a Reply

Your email address will not be published.