## Arrays Basics

Solved
Super Contributor
Posts: 1,041

# Arrays Basics

Hi Team,

I am not good at using arrays.

Below is an example. I want to know the exact meaning of  balance=balance+ (balance*rate{month});

I also was having the notion that when evet i use an array statement I had to go for do i=1 to n;

In the below example there was no need of it and got the answer.

Thanks

data trial;
input balance month;
cards;
500 3

500 4

760 2

500 1

800 3

400 6

500 6

300 7

;

run;

data trial2;

set trial;

array rate {6} _temporary_  (0.05  0.08  0.12  0.20  0.27  0.35);

if month ge 1 and month le 6 then

balance=balance+ (balance*rate{month});

run;

OUTPUT:

balance  month

500          3

600          4

820.8       2

525           1

896          3

540          6

675          6

300           7

Accepted Solutions
Solution
‎09-25-2012 02:24 PM
Super Contributor
Posts: 1,636

## Re: Arrays Basics

Posted in reply to robertrao

Hi Karun,

your output is incorrect.

with "rate {6} _temporary_  (0.05  0.08  0.12  0.20  0.27  0.35);"

we have rate1=0.05,rate2=0.08 ... ,rate6=0.35.

first observation (balance=500, month=3):

balance=500 +(500*rate(3))=500+(500*0.12)=560

All Replies
Super Contributor
Posts: 1,041

## Re: Arrays Basics

Posted in reply to robertrao

I was thinking that the position in the rate corresponds to value of the month when we write rate{month}.

Please correct me if I am wrong???

Also why there is no need of a do i= step??????????

Thanks

Solution
‎09-25-2012 02:24 PM
Super Contributor
Posts: 1,636

## Re: Arrays Basics

Posted in reply to robertrao

Hi Karun,

your output is incorrect.

with "rate {6} _temporary_  (0.05  0.08  0.12  0.20  0.27  0.35);"

we have rate1=0.05,rate2=0.08 ... ,rate6=0.35.

first observation (balance=500, month=3):

balance=500 +(500*rate(3))=500+(500*0.12)=560

Super Contributor
Posts: 1,041

## Re: Arrays Basics

Good Linlin,

I made a typo i a hurry. shd have been 560

Thanks

Super Contributor
Posts: 1,041

## Re: Arrays Basics

So the position number for example 0.20 holds a position 4

so this value is to be taken for multiplication if the month value  is 4?????????

Thats the meaning of rate{month}.???????????????

Thanks

Super Contributor
Posts: 1,636

## Re: Arrays Basics

Posted in reply to robertrao

Yes. That is correct.

Super Contributor
Posts: 1,041

## Re: Arrays Basics

Great help Linlin

Thanks

Super Contributor
Posts: 1,041

## Re: Arrays Basics

Also why was there no need of a do loop

do i=1  to n????????????

Thanks

Posts: 3,805

## Re: Arrays Basics

Posted in reply to robertrao

An array is just a variable list that you reference with an index.  Usually we use an array so we can do the same operation OVER the entire ARRAY (list of variables).  But that is not always the case as in your example where the index comes from the value of month and changes for each observation.  In this case it serves as a lookup table.  Also since your array is temporary there is no actual variable list, but that doesn't change how the elements are referenced.

Super Contributor
Posts: 1,041

## Re: Arrays Basics

Posted in reply to data_null__

Thanks data_null_

for your detailed explanation

PROC Star
Posts: 7,657

## Re: Arrays Basics

Linlin: Reply to this post so that I can be the first one to congratulate you for attaining Master status!

Super Contributor
Posts: 1,041

## Re: Arrays Basics

I can ask linlin another one.if she doesnt mind.............jus kidding.

You are all very helpful

Super Contributor
Posts: 1,041

## Re: Arrays Basics

Hi Arthur,

I have a problem understanding the code. It was answerd in the Forum and they said this is one of the classic examples. I posted it yesterday but there was no response. Could you help me with that please. If i get your consent I can post it again.

Thanks

Super Contributor
Posts: 1,636

## Re: Arrays Basics

Thank you Art and I just bought the whole thing to make wine or mead (Starter
Winemaking Equipment Kit w/ Floor
)! - Linlin

PROC Star
Posts: 7,657

## Re: Arrays Basics

Congratuations!  Send me a bottle when its ready!

🔒 This topic is solved and locked.

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

Discussion stats
• 17 replies
• 469 views
• 6 likes
• 4 in conversation