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
A
ReplyDeleteA
ReplyDeleteAnswer is A
ReplyDeletecan anyone expalin this.
ReplyDeletePDV 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.
ReplyDeletethank you for the explanation
Deletecould 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?
ReplyDeleteFor 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.
ReplyDeleteI got an answer sheet has B picked up for answer. Not sure How it got it? which picks NonPyaing = 10.
ReplyDeleteI can not relate this 10 with the sum statement. What is the logic for choosing B?
It is 100 answer A. I ran the code.
ReplyDeleteGot 100 when I ran the code.
ReplyDeleteNonPaying 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!
the sum fonction don't calculate the missing value!
ReplyDeleteso 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 ^^)
B
ReplyDeleteAns is A
ReplyDeleteExplanation--> Missing values in the summary functions are ignored and considered as 0.
Hence 0+Something=Something.
I CHECKED AND THE ANSWER IS D BUT WHY
ReplyDeleteu 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
DeleteTotal=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
Ans is 100 why becoz sum function is being used
ReplyDeleteTotalPassengers = sum (OrigPassengers, TransPassengers); as per prgm: origpass is . (missing) and transpass is 100 so sum function returns 100 as ignores missing value.
A
ReplyDeleteA
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteA
ReplyDeleteIn 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.
ReplyDeleteA
ReplyDeleteTOTAL=SUM(.,100)=100 SINCE AG-NOR .
ReplyDeleteTHE ANSWER IS A
ReplyDeletewhen I tried this in SAS there is missing value for TotalPassengers why?
ReplyDelete