BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
JKim8069
Calcite | Level 5
11.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
At the end of the 15th iteration of the DO loop, the value for Year is incremented to 2005

Dear guys, can I know why it’s not 2004?
1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
Jade | Level 19

The index variable (YEAR in your example) is incremented by 1 at the end of each iteration.  The looping will not stop until the index variable is outside of the range (1990 through 2004 in your example).

 

So, in the last iteration YEAR=2004, a valid value.  At the end of that iteration, it is incremented to 2005, at which point the index variable first becomes outside of range., and no more loops are executed.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

1 REPLY 1
mkeintz
Jade | Level 19

The index variable (YEAR in your example) is incremented by 1 at the end of each iteration.  The looping will not stop until the index variable is outside of the range (1990 through 2004 in your example).

 

So, in the last iteration YEAR=2004, a valid value.  At the end of that iteration, it is incremented to 2005, at which point the index variable first becomes outside of range., and no more loops are executed.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 146 views
  • 1 like
  • 2 in conversation