turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Sigma Summation in sas

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2015 05:08 AM

How do we go about inserting mathematical functions like this into sas? Sum(i in 1 to n-2) (** Floor (n/ ) where n is just the natural numbers.*

I just want to output two columns, one for the natural numbers and one for out come of the summation above.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2015 08:11 AM

This formula could be part of a DO loop in a data step. You could also program this in loop in PROC IML.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2015 09:11 AM

data some_numbers;

n=0;

a=0;

b=0;

do while(n<1000);

a= (here is my problem, I want a to be Sum(i in 1 to n-2) (** Floor (n/ )*)

output;

n=n+1;

end;

run;

my over all aim is just to have two columns, one with just n=0 to 1000 or so, and the second column is (a) as above. however my above code wouldn't accept this difficult for (a).

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2015 10:32 AM

Provide what you are expecting for the first 3 or 4 outputs (at least). I suspect you may not be expressing your problem quite concisely.

You can factor out the ** bit as a constant times each member of series: * (first term) + *(second term + ... +*(nth term) = * sum of terms. So * sum of Floor(n/).*

HOWEVER: You have issues with the value of * is going to hit 0 in three iterations as n-2 will be -2 , -1 and 0 and hence undefined.*

Maybe you want to start with n=3?

I think you are looking, in a more general sense for :

do while(n<1000);

a=0;

do i =1 to (n-2);

a= a+ (i* Floor (n/i));

end;

output;

n=n+1;

end;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2015 10:40 AM

It sounds like you're treating your data like a matrix and may want to look at SAS/IML.

BASE/SAS programming doesn't quite work the same way, so you need to change the way you think a bit. It process each line and then moves onto the next, with exceptions that can be programmed in. This method means it doesn't need to read all of the data into memory which is why it handles big data with the same code as small data in a straightforward manner.

At any rate, you need to go back to basic looping structures then when you want to do summations. Post an example of the data you have and the output you expect. If you're looking to use SAS/IML which is closer to R then mention that as well.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2015 02:25 PM

The data step is easy:

data series;

do n = 3 to 10;

sum = 0;

do i = 1 to n-2;

sum = sum + i/ floor(n/i);

end;

output;

end;

keep n sum;

run;

proc print;run;

In IML, you can loop over the values of n:

proc iml;

n = T(3:10);

sum = j(nrow(n),1);

do k = 1 to nrow(n);

i = 1n

sum

end;

print n sum;

If you want to get fancy, you can also do compute the summations for all values of n without any loops by using matrices.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-23-2015 09:41 AM