Hi SAS Forum,
I have below data set.
data acct_li;
input old_lmt authorized_limit ;
cards;
700 1000
800 1500
5000 5000
100 110
7000 6000
;
run;
A previous worker has applied the follwoing code on the above data set.
data t_review1;
set acct_li ;
retain ActNum limitIcs 0;
if (authorized_limit>old_lmt) then do;
ActNum+1;
limitIcs=sum(limitIcs, (authorized_limit-old_lmt));
output;
end;
run;
proc print;
run;
Above code produced the following output.
old_limit authorized_limit ActNum limitIcs /*these are the table headings*/
700 | 1000 | 1 | 300 |
800 | 1500 | 2 | 1000 |
100 | 110 | 3 | 1010 |
Q: Of the above code, I cannot understand how the below sum function portion is happening.
limitIcs=sum(limitIcs, (authorized_limit-old_lmt));
The red color "limitIcs" in the above sum function was never calculated before, but in the sum function we are asking the fucntion to add limitIcs to (authorized_limit-old_lmt);
How come it happens?
Please help me to understand it.
Thanks
Mirisa
Yes, what I proposed is the sum statement. If you look at the documentation ( SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition ), the sum statement is the equivalent of using the sum function together with a retain statement. I misspoke when I referred to it as the sum function (which I will correct in my original response).
The sum function not only adds, but ignores missing values.
The code could also have been written:
limitIcs+(authorized_limit-old_lmt);
and have the same result since it is another way of accomplishing the same task as the sum function but, additionally, retains the summed variable without requiring a retain statement.
Hi Art,
Thank you very much for your inputs.
Yes, your alternate code which is
limitIcs+(authorized_limit-old_lmt); /*this looks like sum statement*/
produced the same results produced by
limitIcs=sum(limitIcs, (authorized_limit-old_lmt)); /* this is sum function*/
However, I am still confused (due to lack of my knowledge).
Green one is the "sum function" that was originally in the code I provided. You have changed it to the Yellow one which looks like "sum statement".
So, would this mean "sum function's" duty can also be achieved by "sum statement".
Thanks
Mirisa
If you look at the SAS documentation on the sum function it adds up each value placed within the brackets separated by commas. So in your example the brackets indicate that the code with should be done first, i.e. old_lmt value is taken off authorized_limit. This is then added to limilcs. So we could reword as:
limitlcs = add these items together ( limitlcs and the result of authorized_limit minus old_lmt)
Yes, what I proposed is the sum statement. If you look at the documentation ( SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition ), the sum statement is the equivalent of using the sum function together with a retain statement. I misspoke when I referred to it as the sum function (which I will correct in my original response).
Hi Art and RW9,
Many thanks to both of you.
Regards
Mirisa
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!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.