## ElearnSAS.com

SAS Learning Platform

### Base SAS 82

The SASDATA.BANKS data set has five observations when the following SAS program is submitted:
libname sasdata 'SAS-data-library';
data allobs;
set sasdata.banks;
capital=0;
do year = 2000 to 2020 by 5;
capital + ((capital+2000) * rate);
output;
end;
run;
How many observations will the ALLOBS data set contain?
A. 5
B. 15
C. 20
D. 25

1. Anonymous10:34 AM

roshini ur right baby

2. i think its C....2000 to 2020 by 5. so, 4 iterations..

3. Anonymous1:27 PM

D

year=2000 to 2020 by 5
(includes the 2020 also, so 5 iterations)

4. sas user5:50 AM

D

2000
2005
2010 2015
2020

5. Anonymous5:35 PM

D
5*5=25

6. D

5 observations 5 iterations

7. Anonymous9:20 PM

8. Anonymous3:41 PM

d

9. Anonymous7:46 PM

A

10. Anonymous7:47 PM

D

11. because the output statement is inside the do loop, an observation will be created each time through the loop, so 5 observations, 5 loops, 25 observations total

12. sweta4:29 PM

Because of output statement 5 observations are created otherwise only one.

try the below SAS statement:-
data allobs;
rate=0.1;
capital=0;
do year = 2000 to 2020 by 5;
capital + ((capital+2000) * rate);
end;
run;

data banks;
input num;
datalines;
1
2
3
4
5
;
run;

data allobs;
set banks;
rate=0.1;
capital=0;
do year = 2000 to 2020 by 5;
capital + ((capital+2000) * rate);
output;
end;
run;

NOTE: There were 5 observations read from the data set WORK.BANKS.
NOTE: The data set WORK.ALLOBS has 25 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.02 seconds

14. Anonymous3:38 PM

@ sweta,
u missed d the explicit ouptput statement in the do loop. due to this explicit output staemnt in the do loop there will be 5 obsn for each obsn in the bank dataset, so the total of obsn in the new dataset allobs will be (5*5)=25
>> joydeep786@gmail.com

1. Anonymous12:08 PM

hi im just confused why 5 iteration for each obs? i know its bcuz of the output in the do loop......but is it bczu of the by 5 or sth so that each obs get 5 output?

15. ani ....4:43 PM

ans is D its a good one .
my mail
lotlikar.aniket44@gmail.com

16. Anonymous4:37 PM

Why are you guys giving out your email ids?? I don't anyone is interested in mailing dudes. Girls are most welcome to share their emails please. That behavior is highly encouraged.

Answer is D. A good question after a long while.

17. Anonymous7:19 AM

corrrect me if i'm wrong, but
it's INOCREMENTED by 5.
so 2000, 2005, 2010, 2015, 2020 (total of 5)

for those who argue that it's 5obs*5iterarion
isn't that the case when it's NESTED DO LOOP?

correct me if i'm wrong.

18. Ans is A....
plz dont post without cross checking the ans...it will be confusing
try this code :
data allobs;
rate = 0.5;
capital=0;
do year = 2000 to 2020 by 5;
capital + ((capital+2000) * rate);
output;
end;
run;
proc print ;
run;

19. Anonymous8:47 AM

There was question and answer sheet on web it says 25 but trying to find why 25?
SAScert;

Can you give us the reasons for adding datelines;
1
2
3
4
5
; why we need this ?
Because increment by 5 thefefore we added 5 datalines?

1. Anonymous4:26 PM

Dude question says, dataset bank has 5 observations. If you take only one observation then A will be r8.

20. Anonymous2:45 AM

D is right,we r copying one data set to another dataset.there were 5 observations and for each obs the loop runs one time. so for one obs it will take 5 iterations .... for better understanding use macros with MLOGIC option ....

thank u
Chiru

1. Anonymous12:11 PM

why 5 iterations for each obs.....bcuz of the by 5?

21. priyanka12:33 AM

the do loop will execute 5 times(2000,2005,2010,2015,2020)for each observation of the sasdata.banks data set.

therefore,
=5(observation of sasdata.bank)*5(times do loop execution)
=25 !!

1. Anonymous12:12 PM

why 5 times for each obs? not 1 or some different number?

22. Anonymous12:21 PM

Anyone who said anything other than D is wrong. Please try this code:
Data employee;
input id salary name\$ location\$12.;
cards;
101 8500 asim bangalore
102 45 ravi chennai
104 899 siva US
107 675 rajesh hubli
run;

data allobs;
set employee;
rate=0.1;
capital=0;
do year = 2000 to 2020 by 5;
capital + ((capital+2000) * rate);
output;
end;
run;

Remove the output statement or put the output outside the do look. The allobs dataset will have 5 observations.

23. Ans is 5 its sad by 5 means every tme ts increment by 5 so only 5 observaton.

24. Ans : D

Example :

data banks;
input rate;
datalines;
0.1
0.2
0.3
0.4
0.5
;
run;

data allobs;
set banks;
capital=0;
do year = 2000 to 2020 by 5;
capital + ((capital+2000) * rate);
output;
end;
run;

Proc Print;
run;

Log :

145
146 data banks;
147 input rate;
148 datalines;

NOTE: The data set WORK.BANKS has 5 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.01 seconds

154 ;
155 run;
156
157 data allobs;
158 set banks;
159 capital=0;
160 do year = 2000 to 2020 by 5;
161 capital + ((capital+2000) * rate);
162 output;
163 end;
164 run;

NOTE: There were 5 observations read from the data set WORK.BANKS.
NOTE: The data set WORK.ALLOBS has 25 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.13 seconds
cpu time 0.04 seconds

165
166 Proc Print;
167 run;

NOTE: Writing HTML Body file: sashtml3.htm
NOTE: There were 25 observations read from the data set WORK.ALLOBS.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.12 seconds
cpu time 0.01 seconds

25. Out Put :

Obs rate capital year
1 0.1 200.00 2000
2 0.1 420.00 2005
3 0.1 662.00 2010
4 0.1 928.20 2015
5 0.1 1221.02 2020
6 0.2 400.00 2000
7 0.2 880.00 2005
8 0.2 1456.00 2010
9 0.2 2147.20 2015
10 0.2 2976.64 2020
11 0.3 600.00 2000
12 0.3 1380.00 2005
13 0.3 2394.00 2010
14 0.3 3712.20 2015
15 0.3 5425.86 2020
16 0.4 800.00 2000
17 0.4 1920.00 2005
18 0.4 3488.00 2010
19 0.4 5683.20 2015
20 0.4 8756.48 2020
21 0.5 1000.00 2000
22 0.5 2500.00 2005
23 0.5 4750.00 2010
24 0.5 8125.00 2015
25 0.5 13187.50 2020

@Zakku, why do you have five observations for rate? Not one or six? If we choose six observations for rate, the answer would be 30.

In my view, we can assume a unique value for rate; the answer would be five (A).

27. what wa the answer?? why 25??

1. 5 observations from input dataset, each observation is outputted 5 times by do loop, so 5*5 = 25 obs.

28. Anonymous12:14 PM

sorry all but im just confused why is it 5 iteration for each obs bcuz of the output in do loop; not a different number of iteration?

29. An understanding of PDV can clear the doubts of all who are confused. Ans is D

30. THE CORRECT ANSWERS IS A..

RUN THE BELOW MENTIONED CODING AND YOU WILL GET THE ANSWER

IF THE OUTPUT IS OUTSIDE THE LOOP ONLY ONE OBSERVATION COMES OUT.

data allobs;
set sasdata.banks;
capital=0;
do year = 2000 to 2020 by 5;
capital + ((capital+2000) * rate);
output;
end;
run;

36 data allobs;
37
38 capital=0;
39 do year = 2000 to 2020 by 5;
40 capital + ((capital+2000) * rate);
41 output;
42 end;
43 run;

NOTE: Variable rate is uninitialized.
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
5 at 40:27
NOTE: The data set WORK.ALLOBS has 5 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.06 seconds

31. remove the set statement from it it will still give the same no of iterations

32. ans is d.

Try this code

proc sql;
create table work.banks (
rate integer,
Var2 varchar(30));

insert into work.banks values (10, 'one');
insert into work.banks values (20, 'two');
insert into work.banks values (1, 'three');
insert into work.banks values (4, 'four');
insert into work.banks values (8, 'five');
quit;

data allobs;
set work.banks;
capital=0;
do year = 2000 to 2020 by 5;
capital + ((capital+2000) * rate);
output;
end;
run;