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

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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).

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

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.



Mirisage
Obsidian | Level 7

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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)

art297
Opal | Level 21

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).

Mirisage
Obsidian | Level 7

Hi Art and RW9,

Many thanks to both of you.

Regards

Mirisa

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 929 views
  • 6 likes
  • 3 in conversation