If so, then Proc Expand is the right tool.
data have;
do a = 1 to 20;
output;
end;
run;
proc expand data = have(where = (a ne 1)) out = want;
id a;
Convert a = b / transformout = (reverse movsum 3 reverse);
run;
Result:
a b 2 9 3 12 4 15 5 18 6 21 7 24 8 27 9 30 10 33 11 36 12 39 13 42 14 45 15 48 16 51 17 54 18 57 19 39 20 20
Do you have SAS/ETS?
If so, then Proc Expand is the right tool.
data have;
do a = 1 to 20;
output;
end;
run;
proc expand data = have(where = (a ne 1)) out = want;
id a;
Convert a = b / transformout = (reverse movsum 3 reverse);
run;
Result:
a b 2 9 3 12 4 15 5 18 6 21 7 24 8 27 9 30 10 33 11 36 12 39 13 42 14 45 15 48 16 51 17 54 18 57 19 39 20 20
Hi yes, I need a running sum...for example
Pd
0 |
0.0003 |
0 |
0 |
0 |
0 |
0 |
1.25E-05 |
4.32E-05 |
4.32E-05 |
4.43E-05 |
4.43E-05 |
4.43E-05 |
0.000132 |
0.000132 |
0.000132 |
0.000135 |
0.000135 |
0.000134 |
0.000139 |
0.000139 |
0.000139 |
0.000142 |
0.000142 |
0.000142 |
0.00021 |
0.00021 |
0.00021 |
0.000203 |
0.000202 |
0.000202 |
0.000194 |
0.000194 |
0.000194 |
0.000185 |
0.000185 |
0.000185 |
leaving the first value i need sum from 2nd position to 13 position basically i need sum of 12 months pd.
Then I need sum from 3rd position to 14th position then 4th to 15th position likewise till there are less than 12 values left
Thanks for your support!
Perhaps you meant SKIPPING the first one? You don't seem to have left it as you did not include it in the output.
Let's make on input dataset named HAVE with the variable A you describe.
data have;
do a=1 to 20;
output;
end;
run;
Now let's make a new dataset with the sum groups of three observations starting from the second observation.
data want;
do n=1 to 3;
set have(firstobs=2);
b=sum(b,a);
end;
drop n;
run;
That results that differ from your example output. 9 18 27 36 45 54
So perhaps you meant something other than what you said? Perhaps you meant you want a running sum of the last three values?
data want;
set have;
b + a;
b + -lag3(a);
if _n_ >= 4;
* put b @;
run;
That results in the series 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57
Hi yes, I need a running sum...for example
Pd
0 |
0.0003 |
0 |
0 |
0 |
0 |
0 |
1.25E-05 |
4.32E-05 |
4.32E-05 |
4.43E-05 |
4.43E-05 |
4.43E-05 |
0.000132 |
0.000132 |
0.000132 |
0.000135 |
0.000135 |
0.000134 |
0.000139 |
0.000139 |
0.000139 |
0.000142 |
0.000142 |
0.000142 |
0.00021 |
0.00021 |
0.00021 |
0.000203 |
0.000202 |
0.000202 |
0.000194 |
0.000194 |
0.000194 |
0.000185 |
0.000185 |
0.000185 |
leaving the first value i need sum from 2nd position to 13 position basically i need sum of 12 months pd.
Then I need sum from 3rd position to 14th position then 4th to 15th position likewise till there are less than 12 values left
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.