Statements within the DATA step execute in order. Leaving out TransPassengers from the analysis, that means:
(1) set OrigPassengers to 100
(2) set OrigPassenters to .
(3) compute TotalPassengers
At the time TotalPassengers is computed, OrigPassengers is missing.
Missing + 100 + 0 = 100
If you move your IF statement further down, the answer will be 200.
Statements within the DATA step execute in order. Leaving out TransPassengers from the analysis, that means:
(1) set OrigPassengers to 100
(2) set OrigPassenters to .
(3) compute TotalPassengers
At the time TotalPassengers is computed, OrigPassengers is missing.
@pchen002 wrote:
The following SAS program is submitted:data work.passengers;if OrigPassengers = . thenOrigPassengers = 100;TransPassengers = 100;OrigPassengers = .;TotalPassengers = sum (OrigPassengers, TransPassengers) +0;run;What is the value of the TOTALPASSENGERS variable in the output data set?Answer is 100, why not 200??Please help, thanks!!!
Why should it be 200? In the sum() function, missing values are considered zero.
Start reading the f*cking documentation, your continuing questions on extremely simple issues start to reveal you as a person with an allergy to think on your own.
@pchen002 Although this is a open technical forum, Kindly do not consider this as school homework forum or education forum. The spirit of the discussions should be kept interesting for everybody, which means both the original poster as well as for responders. The questions that you post will add really no value to many if not all.
Ok... @Kurt_Bremser I think there's a bit of piling on here that needs to stop. Not that the point isn't correct but this seems to cross over the considerate/polite boundary. Please remember that you're not required to respond and that's the best way to not support this type of behaviour. And yes, I've done this myself at times, so I do get it 😉
@pchen002 please use some consideration in your posts. Here's a post that explains how to post good questions https://stackoverflow.com/help/how-to-ask
If you're genuinely attempting to learn please show an attempt and you'll find a lot of support and help. But so far, you've posted questions, not responded to follow ups and the questions are literally copy and paste from whatever study material you're using.
And another point - good study material explains the examples/questions and doesn't depend on the free help of others. Consider the SAS certification guide which has fully explained problems and examples. It's worth the small price, or consider checking with your University library or Safari tech books which have the guides.
Good Luck.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.