ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 59

The following SAS program is submitted:
data work.passengers;
if OrigPassengers = . then
OrigPassengers = 100;
TransPassengers = 100;
OrigPassengers = .;
NonPaying = 10;
TotalPassengers = sum (OrigPassengers, TransPassengers);
run;
Which one of the following is the value of the TOTALPASSENGERS variable in the output data set?
A. 100
B. 110
C. 200
D. . (missing numeric value)
Click Comment link to get answer

27 comments:

  1. Anonymous11:11 PM

    Answer is A

    ReplyDelete
  2. can anyone expalin this.

    ReplyDelete
  3. PDV initializes all variables in data step to missing first. So if statement yields true, so value of origpassenger becomes 100. Then transpassenger is assigned value of 100. Next step value of origpassenger is overwritten with missing value. So when you add using sum function which ignores missing value, values of orignpassenger and transpassenger ie sum(.,100) gives you 100. Thus answer is A.

    ReplyDelete
    Replies
    1. thank you for the explanation

      Delete
  4. Anonymous1:18 PM

    could someone explain why is not 200? at the beginning it says that if orignpassenger is missing then it will be equal to 100. then later it's set to missing. doesn't sas assigns it a value of 100 since we told it before in the program that if it was missing then the value should be 100?

    ReplyDelete
  5. Anonymous8:30 AM

    For one observation, SAS only iterates the code one time by default. So, once if missing set 100 statement is executed, SAS does not remember it and converts it back to 100 whenever it is changed to missing. Now read SASCERT explanation above.

    ReplyDelete
  6. Anonymous3:11 PM

    I got an answer sheet has B picked up for answer. Not sure How it got it? which picks NonPyaing = 10.
    I can not relate this 10 with the sum statement. What is the logic for choosing B?

    ReplyDelete
  7. Anonymous5:57 PM

    It is 100 answer A. I ran the code.

    ReplyDelete
  8. Remya1:08 PM

    Got 100 when I ran the code.

    NonPaying is not used in the calculation for TotalPassengers at all!

    Learned something here - Looks like an if statement can be used to initialize the value of a new variable :) First origpassengers value was initialized. In the second if statement the transpassengers value was initialized.

    Good info!

    ReplyDelete
  9. Anonymous2:46 PM

    the sum fonction don't calculate the missing value!
    so the sum will only count the value of 'TransPassengers'

    the other will take the value of the last insctruction so OrigPassengers=.

    (sorry for my english ^^)

    ReplyDelete
  10. Ans is A

    Explanation--> Missing values in the summary functions are ignored and considered as 0.
    Hence 0+Something=Something.

    ReplyDelete
  11. Anonymous1:59 PM

    I CHECKED AND THE ANSWER IS D BUT WHY

    ReplyDelete
    Replies
    1. Anonymous3:59 PM

      u r referring to a wrong question, the question u saw was not using sum instead, just + (TotalPassengers = OrigPassengers + TransPassengers) which throws '.' if one of the value is '.'

      Delete

    2. Total=Sum(a,b,c);

      i.e. sum function ignore the missing values '.' , if c is missing then sum function take value of c is 0 and and it adds the a & b .

      Here, the correct ans is A

      Delete
  12. Ans is 100 why becoz sum function is being used
    TotalPassengers = sum (OrigPassengers, TransPassengers); as per prgm: origpass is . (missing) and transpass is 100 so sum function returns 100 as ignores missing value.

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. Anonymous11:04 AM

    In this case the answer should be A. since the if statement has been executed, so when the code assign missing to the OrigPassengers the value will not become 100.

    ReplyDelete
  15. Anonymous9:13 PM

    TOTAL=SUM(.,100)=100 SINCE AG-NOR .

    ReplyDelete
  16. Anonymous9:14 PM

    THE ANSWER IS A

    ReplyDelete
  17. Anonymous10:56 AM

    when I tried this in SAS there is missing value for TotalPassengers why?

    ReplyDelete