BookmarkSubscribeRSS Feed
ManitobaMoose
Quartz | Level 8

Hi,

 

I am working through testprep ques for the base exam. I will always go through all of them to see if I understand the answer. In the cases that I don't, I will ask for help on here.

 

So far, pasted below, is the code from the first question I don't understand the answer to.

Question 5
The following SAS program is submitted: 
data WORK.LOOP; 
  X = 0; 
  do Index = 1 to 5  by  2; 
    X = Index; 
  end; 
run; 
Upon completion of execution, wha
t are the values of the variab
les X and Index in
 the SAS data set 
named WORK.LOOP? 
A. X = 3, Index = 5 
B. X = 5, Index = 5 
C. X = 5, Index = 6 
D. X = 5, Index = 7 
correct_answer = "D"

I would have thought that when Index reached 5, and X was 5, that, even though the do loop is still active, that the index would not be allowed to go above 5. It appears that it can go beyond the limits set in the By statement in such a case. Is that correct? I would have chosen answer B. Thanks.

 

 

3 REPLIES 3
ManitobaMoose
Quartz | Level 8

I meant to say, not "set in the By statement" but rather beyond the limits set in the Index = statement.

Astounding
PROC Star

In that DO loop, the question is how does INDEX go from 1 to 5.  The process is:

 

  • Go through the loop with INDEX equal to 1.
  • At the END statement, add 2 to the value of INDEX.
  • See if the loop is now over.  (This would happen if INDEX exceeds the upper limit of 5.)
  • If the loop should continue, execute again.

So as you might expect, the loop executes 3 times with INDEX being 1, 3, and 5.  (You can see those values captured in the variable  X.)

 

At the END statement, the third time through the loop, the same process is applied.  Add 2 to the value of INDEX, giving it a value of 7.  SAS now notices that 7 is greater than the upper limit of the loop (1 to 5), so the loop ends.

 

You can see this at work by adding this statement twice:

 

put x= index=;

 

Add it once before the END statement, and again after the END statement.

The final value of INDEX always exceeds the upper limit in the DO statement.

Suhani
Calcite | Level 5
Hii, Will you be kind enough to send me the link to more of questions like this to practice? I have an upcoming SAS BASE exam and I would really appreciate some help regarding resources to practice for the exam. Thanks in advance.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2324 views
  • 2 likes
  • 3 in conversation