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

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.

Please help me understand

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

      

View solution in original post

17 REPLIES 17
robertrao
Quartz | Level 8


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

Linlin
Lapis Lazuli | Level 10

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

      

robertrao
Quartz | Level 8

Good Linlin,

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

Thanks

robertrao
Quartz | Level 8

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

Linlin
Lapis Lazuli | Level 10

Yes. That is correct.

robertrao
Quartz | Level 8

Great help Linlin

Thanks

robertrao
Quartz | Level 8

Also why was there no need of a do loop

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

Thanks

data_null__
Jade | Level 19

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.

robertrao
Quartz | Level 8

Thanks data_null_

for your detailed explanation

art297
Opal | Level 21

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

robertrao
Quartz | Level 8

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

You are all very helpful

robertrao
Quartz | Level 8

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

Linlin
Lapis Lazuli | Level 10

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

art297
Opal | Level 21

Congratuations!  Send me a bottle when its ready!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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