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

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
  • 2 replies
  • 2066 views
  • 0 likes
  • 3 in conversation