BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Steelers_In_DC
Barite | Level 11

Good Afternoon All, It's been a while since I've posted.  I'm studying for the base sas certification and depending on who I talk to it's either very easy or impossible.  I'm doing my best to gather study info from the interwebs, what sas provides seems like a lot of softballs compared to what the practice exams online look like.  I came across the following and don't understand it.  If you can help I'd appreciate it, any additional info regarding preparing for the certification is welcome also.

Thanks,

Why does the following contain 25 observations:

data allobs;

     set sasdata.banks;

          capital=0;

          do year = 2000 to 2020 by 5;

          capital + ((capital+2000) * rate);

          output;

     end;

Mark

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

the do loop outputs five times and there must be five observations in the dataset sasdata.backs. 5*5=25

data banks;

input rate;

cards;

.05

.06

.07

.08

.09

;

data allobs;

    set banks;

          capital=0;

          do year = 2000 to 2020 by 5;

          capital + ((capital+2000) * rate);

          output;

     end;

run;

proc print;run;

View solution in original post

4 REPLIES 4
DBailey
Lapis Lazuli | Level 10

I don't have a sasdata.banks, but I suspect it has 5 observations in it  For each observation, the loop is executed 5 times so 5 * 5=25.

data_null__
Jade | Level 19

It is due to the placement of the OUTPUT statement.  5 obs output for each obs in SASDATA.BANKS.

Linlin
Lapis Lazuli | Level 10

the do loop outputs five times and there must be five observations in the dataset sasdata.backs. 5*5=25

data banks;

input rate;

cards;

.05

.06

.07

.08

.09

;

data allobs;

    set banks;

          capital=0;

          do year = 2000 to 2020 by 5;

          capital + ((capital+2000) * rate);

          output;

     end;

run;

proc print;run;

Steelers_In_DC
Barite | Level 11

Thanks, spelling it out like that helped a great deal.  Running the program and looking at the log/output always helps.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1682 views
  • 3 likes
  • 4 in conversation