BookmarkSubscribeRSS Feed
apat86
Calcite | Level 5
Hello,

I have 365 variables each for a day in particular year (i.e. Jan01--Dec31). I need to find sum of 60 days only. I used array statement to find sum, but i need to mansion all 60 variables. Can I use "Total=Sum (of var {i+1}--var{i+60})" ? It is not working with my program.

Any suggestions highly appreciated.

Thank you..
2 REPLIES 2
ArtC
Rhodochrosite | Level 12
While you can't use array values as list elements, you can do what you want by using a stack. The stack avoids a loop that passes through the array multiple times.

The following silly program creates the first sum and then for each successive sum removes the oldest value and adds the newest (FIFO stack).
[pre]
data days(keep=day:);
array days {366} day1-day366;
do i = 1 to 365;
days{i} = 1;
end;
output;
run;

data sums(keep=period sum);
set days;
retain sum .;
array days {366} day1-day366;
period=1;
sum = sum(of day1-day60);
output;
do period = 2 to 306;
sum = sum(of sum, -days{period-1},days{period+60});
output sums;
end;
run;[/pre]
Ksharp
Super User
Hi.
Not sure what variables you need to sum.
But SUM function supports not only list input but also colon input.
For example you need to sum January and February.
[pre]
sum(of jan: feb:)
[/pre]



Ksharp

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2571 views
  • 0 likes
  • 3 in conversation