DATA Step, Macro, Functions and more

Do Loop

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

Do Loop

I am new to SAS, I came cross this question online, I see 2 DO loop statements here, but there is only one "End" statement. Shouldn't it include 2 "End" statements, one for each DO loop? Thanks!

 

Capture.JPG


Accepted Solutions
Solution
‎02-07-2018 12:02 PM
SAS Super FREQ
Posts: 4,113

Re: Do Loop

[ Edited ]

I think they are asking for the output IF the program was correctly written. In that case, the correct answer is C because the last observation is written.  If you want all observations, put an OUTPUT statement inside the innermost loop.

View solution in original post


All Replies
SAS Super FREQ
Posts: 4,113

Re: Do Loop

You are correct. The program will give a syntax error unless it has two END statements.

Occasional Contributor
Posts: 13

Re: Do Loop

Hi Rick, thanks for your reply. In this case, there should be no observation be written. right?  I would choose D as the answer.  But the system says the correct answer is C.

 

Solution
‎02-07-2018 12:02 PM
SAS Super FREQ
Posts: 4,113

Re: Do Loop

[ Edited ]

I think they are asking for the output IF the program was correctly written. In that case, the correct answer is C because the last observation is written.  If you want all observations, put an OUTPUT statement inside the innermost loop.

Occasional Contributor
Posts: 13

Re: Do Loop

Rick, I agree with you. I think this question is to check if you know 'OUTPUT' statement. without the OUTPUT statement, it will only show the last observation.  However, for curiosity I tried to write this program in SAS, Log shows an Error and a Warning as I expected.  

If this is a real exam, I will be confused, what is it trying to test us: OUTPUT statement or End statement.  I am having an exam next week, wish myself goodluck. Smiley Happy 

 

 

Capture.JPG

SAS Super FREQ
Posts: 4,113

Re: Do Loop

Yes, I agree with you. The first task of the test creator is to make the question clear. The creator of this test did not proofread sufficiently. You have every right to feel confused and frustrated by this question.

 

I suspect and hope that your test next week will be clearer. Best wishes for a successful exam!

Occasional Contributor
Posts: 13

Re: Do Loop

Thanks! Smiley Happy 

Have a good day! 

New Contributor
Posts: 2

Re: Do Loop

Hello Rick,

So do you mean by default only the last observation is written unless you put a implicit output in the do end statement to list all loops?

 

Regards,

Karen

SAS Super FREQ
Posts: 4,113

Re: Do Loop

Posted in reply to Karen_sas11

By default, every DATA step contains an implicit OUTPUT statement at the end the step (just before the RUN statement). That is usually what you want when the DATA step contains a SET statement or an INFILE statement or a DATALINES statement. However, this example does not contain any of the usual data input statements. If you want to see each iteration of the DO loop, you should insert an OUTPUT statement at an appropriate location.

New Contributor
Posts: 2

Re: Do Loop

Thanks a lot!

☑ This topic is solved.

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

Discussion stats
  • 9 replies
  • 187 views
  • 1 like
  • 3 in conversation