Solved
Contributor
Posts: 31

# if-then

The following SAS program is submitted:
data work.passengers;
if OrigPassengers = . then
OrigPassengers = 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??

Accepted Solutions
Solution
‎09-30-2017 09:36 PM
Super User
Posts: 6,939

## Re: if-then

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.

All Replies
Frequent Contributor
Posts: 103

## Re: if-then

Missing + 100 + 0 = 100

If you move your IF statement further down, the answer will be 200.

Norman.
SAS 9.4 (TS1M4) X64_7PRO WIN 6.1.7601 Service Pack 1 Workstation

Contributor
Posts: 31

## Re: if-then

Thank you!
Solution
‎09-30-2017 09:36 PM
Super User
Posts: 6,939

## Re: if-then

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.

Contributor
Posts: 31

## Re: if-then

Posted in reply to Astounding
Understood, thank you!!!
Super User
Posts: 10,623

## Re: if-then

pchen002 wrote:
The following SAS program is submitted:
data work.passengers;
if OrigPassengers = . then
OrigPassengers = 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??

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 75

## Re: if-then

Posted in reply to KurtBremser

@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.

Super User
Posts: 24,028

## Re: if-then

Posted in reply to KurtBremser

Ok... @KurtBremser  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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
• 7 replies
• 465 views
• 7 likes
• 6 in conversation