BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cosmid
Lapis Lazuli | Level 10

This is question 5 from the SAS Certification Prep Guide book.

 

5. Which of the following statements is false regarding the program shown below?

data work.invest;

  do year=1990 to 2004;

    Capital+5000;

    capital+(capital*.10);

    output;

  end;

run;

 

a. The OUTPUT statement writes current values to the data set immediately.

b. The last value for Year in the new data set is 2005.

c. The OUTPUT statement overrides the automatic output at the end of the DATA step.

d. The DO loop performs 15 iterations.

 

Correct Answer: b

 

Explanation from the back of the book:

The OUTPUT statement overrides the automatic output at the end of the DATA step. On the last iteration of the DO loop, the value of Year, 2004, is written to the data set.

 

Isn't the correct answer c? 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The way I read your explanation for the original problem, "c" is true.  That makes "c" the wrong answer, because the problem asked which of the following is false.

 

There is a difference between the last YEAR value written to the new data set, and the last YEAR value that occurs anywhere within the DATA step.  The last value (2005) is not written to the output data set in question 5, because there is not OUTPUT at the bottom of that DATA step.

View solution in original post

10 REPLIES 10
Astounding
PROC Star

This time the book is correct.

 

The OUTPUT statement has twofold meaning:

 

  • Output right here, right now, without doing any further work.
  • At the end of the DATA step, don't output anything.  Output only where the OUTPUT statement appears.

So that makes "c" true.

 

The correct answer is "b".  The final value of YEAR once the DO loop is over is 2005.  But that value is not written to the new data set, since there is no longer an automatic output at the end of the DATA step.  The final value that is actually written to the new data set is 2004.

cosmid
Lapis Lazuli | Level 10

Hi Astounding, thanks for the quick reply input!

 

Here's why I think the answer is C.

 

1. From the book, here's what it says about Explicit OUTPUT statements:

To create an observation for each iteration of the DO loop, place an OUTPUT statement inside the loop. By default, every DATA step contains an implicit OUTPUT statement at the end of the step. But placing an explicit OUTPUT statement in a DATA step overrides automatic output, causing SAS to add an observation to the data set only when the explicit OUTPUT statement is executed.

 

It says when the OUTPUT statement is executed. So if the OUTPUT statement is written at the top of the DO loop and is executed then it makes C the wrong answer.

 

2. From question 4 of the book and its answer.

Question 4:

In the data set Work.Invest, what would be the stored value for Year?

data work.invest;

  do year=1990 to 2004;

    Capital+5000;

    capital+(capital*.10);

  end;

run;

a. missing

b. 1990

c. 2004

d. 2005

 

Correct Answer: d

 

You can see that here the value for Year is 2005 but in question 5 it says this is wrong. Unless stored value and the last value for Year are two different values?

PaigeMiller
Diamond | Level 26

b. The last value for Year in the new data set is 2005.

 

If (b) said "The last value for Year is 2005", I would agree that (b) is correct.

 

But that's not what it says. It says "The last value for Year in the new data set is 2005" which is not correct, the last value in the data set is 2004.

 

So I agree that (c) is correct. In fact, I am not aware of a situation where (c) is not correct.

--
Paige Miller
Astounding
PROC Star

The way I read your explanation for the original problem, "c" is true.  That makes "c" the wrong answer, because the problem asked which of the following is false.

 

There is a difference between the last YEAR value written to the new data set, and the last YEAR value that occurs anywhere within the DATA step.  The last value (2005) is not written to the output data set in question 5, because there is not OUTPUT at the bottom of that DATA step.

PaigeMiller
Diamond | Level 26

@Astounding wrote:

The way I read your explanation for the original problem, "c" is true.  That makes "c" the wrong answer, because the problem asked which of the following is false.


Yes, @Astounding, I missed the "false" part of the question. Thanks. 

 

It almost seems like they are trying as hard as they can to trick people into getting the wrong answer. My knowledge of how SAS data steps work is correct, my mistake was in not clearly reading the question carefully. Which to me makes it a bad question.

 

Glad I'm not taking this test.

--
Paige Miller
cosmid
Lapis Lazuli | Level 10

Good news is that if you do want to take the Base certification one day, they have changed it to Base Performance, which requires coding instead of multiple choices. But I know you don't. Because you are in the field longer than I have lived, lol:)

 

I picked C as the answer because the book said But placing an explicit OUTPUT statement in a DATA step overrides automatic output, causing SAS to add an observation to the data set only when the explicit OUTPUT statement is executed. So I thought if the explicit OUTPUT statement is written inside a condition and the condition never met then the OUTPUT statement never had executed and therefore never override the automatic OUTPUT. But in this case, there's no condition, so it doesn't apply, and thinking too much caused me picking out the wrong answer.

 

Btw, Question 7 is even worse.

 

PaigeMiller
Diamond | Level 26

I remember a long time ago trying to become a baseball umpire, and taking the rules test.

 

A question began: "the pitcher is astride the rubber..."

 

I had never seen this word astride, I have never seen it since, and so to me this was a bad question. I knew the rule, I didn't understand the word astride, and so I got the question wrong as I was forced to guess what it means.

--
Paige Miller
cosmid
Lapis Lazuli | Level 10

Thanks for pointing that out! The last value for Year is 2005 but the last value for year stored in the data set is 2004 because of the output statement. I really should read questions more carefully next time before bothering people.

ballardw
Super User

@cosmid wrote:

This is question 5 from the SAS Certification Prep Guide book.

 

5. Which of the following statements is false regarding the program shown below?

data work.invest;

  do year=1990 to 2004;

    Capital+5000;

    capital+(capital*.10);

    output;

  end;

run;

 

a. The OUTPUT statement writes current values to the data set immediately.

b. The last value for Year in the new data set is 2005.

c. The OUTPUT statement overrides the automatic output at the end of the DATA step.

d. The DO loop performs 15 iterations.

 

Correct Answer: b

 

Explanation from the back of the book:

The OUTPUT statement overrides the automatic output at the end of the DATA step. On the last iteration of the DO loop, the value of Year, 2004, is written to the data set.

 

Isn't the correct answer c? 


Since that code can be executed did you try that?

It is very easy to determine that YEAR does not have the value of 2005: Print the data set, view in the table viewer, proc freq, proc means. Almost any method used to actually examine the resulting data will clearly show that Year does not have a value of 2005, whether first, last or any other record.

cosmid
Lapis Lazuli | Level 10

Yup. Tested with and without OUTPUT statement. 

 

with OUTPUT: observations from 1990 to 2004

without OUTPUT: one observation of 2005

 

I now understand the OUTPUT statement better. Thank you!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 3257 views
  • 6 likes
  • 4 in conversation