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.
04-16-2015 09:11 AM
a= (here is my problem, I want a to be Sum(i in 1 to n-2) (* Floor (n/))
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).
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 i =1 to (n-2);
a= a+ (i* Floor (n/i));
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.
04-16-2015 02:25 PM
The data step is easy:
do n = 3 to 10;
sum = 0;
do i = 1 to n-2;
sum = sum + i/ floor(n/i);
keep n sum;
In IML, you can loop over the values of n:
n = T(3:10);
sum = j(nrow(n),1);
do k = 1 to nrow(n);
i = 1n
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.