BookmarkSubscribeRSS Feed
InfoAlisaA
Calcite | Level 5

Hello Everyone,

I was wondering if there was an easy way of doing a sigma summation of 1 to n in SAS?

I have been playing around with DO loops, but I would like to know if there is an easier way or a function I could take advantage of.

I am trying to calculate the sum going from i=0 to k of 3^i/i!

Could anyone let me know if there is a sigma summation function I could take advantage of?

Thanks!

6 REPLIES 6
InfoAlisaA
Calcite | Level 5

This is what I have gotten so far that works the way that I want it to:

data test3;

do i =0 to 10 by 1;

n=sum(3**i/fact(i));

if first.i then cumsum=n;

  else cumsum+n;

output;

end;

run;

proc print data=test3;

run;

If anyone has any other suggestions, please let me know!

Thanks!

Cynthia_sas
SAS Super FREQ

Hi:

  Does this note in the SAS Log concern you?

NOTE: Variable first.i is uninitialized.

cynthia

InfoAlisaA
Calcite | Level 5

Oh, I didn't even look at the log. Should I just initialize my i before the DO loop?

twocanbazza
Quartz | Level 8

i is intialised in the do loop, I don't think you can use first.i in the context you are trying.

PGStats
Opal | Level 21

SUM function is useful mostly when there are many arguments.  You can take advantage of the fact that c = sum(a,b) will yield a number whereas c = a + b will assing a missing value to c if a or b is missing. First.i would mean something to SAS only if there was a BY i statement in your datastep. First.i would take the value TRUE each time i changes value.

The proper symtax would be something like:

data test3;

do i = 0 to 10 by 1;

     cumSum = sum(cumSum, 3**i/fact(i));

     output;

     end;

run;

proc print data=test3;

id i;

run;

PG

PG
Ksharp
Super User

Or use SUM statement.

sum+3**i/fact(i)  ;

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
  • 6 replies
  • 2956 views
  • 0 likes
  • 5 in conversation