BookmarkSubscribeRSS Feed
Cho8
Calcite | Level 5
Yd1d2d3d4d5d6d7d8d9
2012010.010.000.010.000.000.000.010.010.01
2012020.03-0.010.020.010.000.000.010.000.04
2012030.010.000.010.000.000.000.000.000.02
2012040.020.010.000.010.020.000.000.000.01
2012050.010.000.000.020.000.000.010.000.03
2012060.000.010.010.020.000.000.000.000.01
2012070.010.020.000.000.000.000.030.000.02
2012080.010.000.000.010.010.000.020.020.00
2012090.010.010.000.030.000.020.010.000.02
2012100.020.000.000.010.040.030.020.010.04
2012110.010.020.010.000.000.000.000.030.00
2012120.020.000.010.000.010.060.000.020.03
2013010.020.020.000.000.000.000.000.000.02
2013020.000.000.010.000.000.010.000.010.05
2013030.010.010.000.010.000.010.000.010.00
2013040.000.040.010.010.010.030.020.04-0.01

 

I need average for 12 observation for every row..

 

for instance.,

 

for D1..start at row2 to row 14 and average displayed at the bottom of row..

for D2..start at row3 to row15 and average displayed at bottom of row...

for D3 start at row4 to row16 and average at bottom of row...

 

 

for all the variables from D1 until D9..

21 REPLIES 21
PaigeMiller
Diamond | Level 26

I need average for 12 observation for every row.

 

Please clarify this. Do you really mean "I need average for 12 observation for every column."?

--
Paige Miller
Cho8
Calcite | Level 5

its vertical summation..not by column

PaigeMiller
Diamond | Level 26

@Cho8 wrote:

its vertical summation..not by column


It sure seems you want to do this by column, but you say "NOT by column". Can you please explain?

--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

Do you really want the average to be displayed at the bottom of the row? Can you post exactly what you want the result to look like?

Cho8
Calcite | Level 5

for d1... average of 201202 until201302 at bottom..

for d2 ...average of 201203 until 201303 at bottom..

 

and so on..

 

 

it should be vertical sum..

Cho8
Calcite | Level 5
Yd1d2d3d4d5d6d7d8d9
2012010.010.000.010.000.000.000.010.010.01
2012020.03-0.010.020.010.000.000.010.000.04
2012030.010.000.010.000.000.000.000.000.02
2012040.020.010.000.010.020.000.000.000.01
2012050.010.000.000.020.000.000.010.000.03
2012060.000.010.010.020.000.000.000.000.01
2012070.010.020.000.000.000.000.030.000.02
2012080.010.000.000.010.010.000.020.020.00
2012090.010.010.000.030.000.020.010.000.02
2012100.020.000.000.010.040.030.020.010.04
2012110.010.020.010.000.000.000.000.030.00
2012120.020.000.010.000.010.060.000.020.03
2013010.020.020.000.000.000.000.000.000.02
2013020.000.000.010.000.000.010.000.010.05
2013030.010.010.000.010.000.010.000.010.00
2013040.000.040.010.010.010.030.020.04-0.01
2013050.010.000.000.000.000.000.000.010.00
2013060.000.010.000.020.000.020.010.000.00
2013070.010.010.040.010.010.010.000.010.02
2013080.020.000.000.010.010.030.120.000.01
2013090.010.000.010.020.030.030.00-0.010.03
2013100.010.000.000.010.000.010.010.010.00
          
avg0.010.010.010.010.010.010.010.010.02
Kurt_Bremser
Super User

Use PROC REPORT:

data have;
input y $ d1-d9;
datalines;
201201  0.01  0.00  0.01  0.00  0.00  0.00  0.01  0.01  0.01
201202  0.03  -0.01 0.02  0.01  0.00  0.00  0.01  0.00  0.04
201203  0.01  0.00  0.01  0.00  0.00  0.00  0.00  0.00  0.02
201204  0.02  0.01  0.00  0.01  0.02  0.00  0.00  0.00  0.01
201205  0.01  0.00  0.00  0.02  0.00  0.00  0.01  0.00  0.03
201206  0.00  0.01  0.01  0.02  0.00  0.00  0.00  0.00  0.01
201207  0.01  0.02  0.00  0.00  0.00  0.00  0.03  0.00  0.02
201208  0.01  0.00  0.00  0.01  0.01  0.00  0.02  0.02  0.00
201209  0.01  0.01  0.00  0.03  0.00  0.02  0.01  0.00  0.02
201210  0.02  0.00  0.00  0.01  0.04  0.03  0.02  0.01  0.04
201211  0.01  0.02  0.01  0.00  0.00  0.00  0.00  0.03  0.00
201212  0.02  0.00  0.01  0.00  0.01  0.06  0.00  0.02  0.03
201301  0.02  0.02  0.00  0.00  0.00  0.00  0.00  0.00  0.02
201302  0.00  0.00  0.01  0.00  0.00  0.01  0.00  0.01  0.05
201303  0.01  0.01  0.00  0.01  0.00  0.01  0.00  0.01  0.00
201304  0.00  0.04  0.01  0.01  0.01  0.03  0.02  0.04  -0.01
;

proc report data=have;
column y d:;
define y / display;
define d: / analysis mean format=7.2;
rbreak after / summarize;
run;
PeterClemmensen
Tourmaline | Level 20

@Kurt_Bremser, I think this a bit too simple since the window of interest changes for each d1, d2 ... 

Kurt_Bremser
Super User

But it creates the expected output as displayed. I first suspected a need for a rolling window, but the OP seems to want one summary line for all numbers.

Cho8
Calcite | Level 5

for d1..average from 201202 to 201302..

 

for d2 average from 201203 to 201303..

 

for d3 average from 201204 to 201304..

 

 

and so on..

PeterClemmensen
Tourmaline | Level 20

Is this for reporting purposes or do you want a SAS data set like this?

Cho8
Calcite | Level 5

@PeterClemmensen wrote:

Is this for reporting purposes or do you want a SAS data set like this?


Need dataset like that..

Cho8
Calcite | Level 5

please check my post on how result should look like..

Ksharp
Super User

Do you have SAS/IML ? I would like to use IML code for this kind of question.

 

data have;
input y $ d1-d9;
datalines;
201201  0.01  0.00  0.01  0.00  0.00  0.00  0.01  0.01  0.01
201202  0.03  -0.01 0.02  0.01  0.00  0.00  0.01  0.00  0.04
201203  0.01  0.00  0.01  0.00  0.00  0.00  0.00  0.00  0.02
201204  0.02  0.01  0.00  0.01  0.02  0.00  0.00  0.00  0.01
201205  0.01  0.00  0.00  0.02  0.00  0.00  0.01  0.00  0.03
201206  0.00  0.01  0.01  0.02  0.00  0.00  0.00  0.00  0.01
201207  0.01  0.02  0.00  0.00  0.00  0.00  0.03  0.00  0.02
201208  0.01  0.00  0.00  0.01  0.01  0.00  0.02  0.02  0.00
201209  0.01  0.01  0.00  0.03  0.00  0.02  0.01  0.00  0.02
201210  0.02  0.00  0.00  0.01  0.04  0.03  0.02  0.01  0.04
201211  0.01  0.02  0.01  0.00  0.00  0.00  0.00  0.03  0.00
201212  0.02  0.00  0.01  0.00  0.01  0.06  0.00  0.02  0.03
201301  0.02  0.02  0.00  0.00  0.00  0.00  0.00  0.00  0.02
201302  0.00  0.00  0.01  0.00  0.00  0.01  0.00  0.01  0.05
201303  0.01  0.01  0.00  0.01  0.00  0.01  0.00  0.01  0.00
201304  0.00  0.04  0.01  0.01  0.01  0.03  0.02  0.04  -0.01
;

proc transpose data=have out=temp name=y prefix=_;
var d1-d9;
id y;
run;

data temp;
 set temp;
 array x{*} _:;
 count=0;
 do i=1 to 13;
  n=_n_+i;
  if n>dim(x) then leave;
  count+1;
  sum=sum(sum,x{n});
 end;
 _avg=sum/count;
 drop i n count sum;
run;

proc transpose data=temp out=want;
var _:;
id y;
run;


hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 21 replies
  • 2384 views
  • 0 likes
  • 5 in conversation