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
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
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
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
Good Linlin,
I made a typo i a hurry. shd have been 560
Thanks
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
Yes. That is correct.
Great help Linlin
Thanks
Also why was there no need of a do loop
do i=1 to n????????????
Thanks
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.
Thanks data_null_
for your detailed explanation
Linlin: Reply to this post so that I can be the first one to congratulate you for attaining Master status!
I can ask linlin another one.if she doesnt mind.............jus kidding.
You are all very helpful
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
Thank you Art and I just bought the whole thing to make wine or mead (Starter
Winemaking Equipment Kit w/ Floor )! - Linlin
Congratuations! Send me a bottle when its ready!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.