Not applicable
Posts: 0

# help!how to get single variable mean for each year in different year?

I want to calculate the average eps for each stkcd in different year.Following is sample.
stkcd is stock code,rptdt is reportdate of forecast,feps is forecast eps of stock.
Stkcd Rptdt feps
002001 2009-07-20 0.22
002001 2009-07-08 0.01
002001 2009-07-20 0.39
002001 2009-12-30 0.182
002001 2009-12-31 0.21
002001 2009-11-09 0.41
002001 2009-12-18 0.41
002001 2009-10-26 0.51
002001 2009-10-26 0.02
002001 2009-10-26 0.182
002001 2009-10-26 0.21
002001 2004-06-18 0.571
002001 2004-06-22 0.11
002001 2004-06-22 0.131
002001 2004-06-22 0.46
002001 2004-06-22 0.528
002001 2004-06-23 0.08
002001 2004-08-09 0.11
002001 2004-08-09 0.37
002001 2004-08-09 0.79
002003 2009-08-31 0.03
002003 2009-08-31 0.02
002003 2009-08-31 0.09
002003 2009-08-31 0.05
002003 2009-08-31 0.07
002003 2009-04-30 0
002003 2009-04-29 0.07
002003 2009-04-30 0.01
002003 2009-05-08 0.06
002003 2009-07-27 0.05
002003 2009-06-05 0.06
002004 2005-07-18 0.02
002004 2005-07-18 0.015
002004 2005-07-18 0
002004 2005-07-18 0.1
002004 2005-07-18 0.046
002004 2005-07-18 0.06
002004 2005-07-18 0.436
002004 2005-09-19 0.02
002004 2005-09-19 0.1
how can i program?thanks!urgent! a poor girl..............
Super Contributor
Posts: 3,176

## Re: help!how to get single variable mean for each year in different year?

Have you looked at using PROC MEANS with a BY statement.

Scott Barry
SBBWorks, Inc.
SAS Super FREQ
Posts: 9,371

## Re: help!how to get single variable mean for each year in different year?

In addition to Scott's suggestion for PROC MEANS, you could also use PROC TABULATE.

One other item to take care of --- since RPTDT is a date field, you will want to use a FORMAT to restrict the RPTDT to YEAR level only (not use RPTDT down to the DAY level).

Last, if all you want is a report then using PROC MEANS or PROC TABULATE will be sufficient. You can use output sent to the LISTING window, if all you need is a plain report or you can use ODS to create HTML, RTF or PDF report output.

But, if you need to create a SAS dataset of the averages, then you will need to investigate either the ODS OUTPUT statement or the OUTPUT statement for PROC MEANS or the OUT= option for PROC TABULATE.

The example code below shows how to find the average height for each birth year and the average height for every year and gender combination. Documentation for PROC MEANS is here:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a000146728.htm

TABULATE here:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a000146759.htm

cynthia
[pre]
data bday;
infile datalines;
input name \$ bday : yymmdd10. height gender \$;
return;
datalines;
alan 1950/11/15 73 M
bob 1989/01/29 72 M
carl 1983/02/16 76 M
dana 1950/11/17 69 F
eliza 1989/01/19 64 F
fran 1983/02/18 65 F
george 1950/11/14 71 M
harry 1989/01/19 72 M
ian 1983/02/26 74 M
jacqie 1950/11/11 68 F
kathy 1989/01/19 67 F
lulu 1983/02/19 69 F
mark 1953/10/25 71 M
noah 1989/01/19 73 M
oliver 1983/02/26 75 M
paula 1950/11/29 65 F
quentin 1989/02/23 73 M
rosie 1984/03/17 66 F
tom 1953/10/12 75 M
uma 1989/02/19 68 F
victor 1983/02/26 72 M
wayne 1950/10/11 73 M
xavier 1989/03/13 76 M
yanni 1983/04/16 72 M
zenia 1984/10/16 54 F
;
run;

proc means data=bday mean;
title '1a) MEANS Average Height for each birth year';
var height;
class bday;
format bday year4.;
run;

proc means data=bday mean;
title '1b) MEANS Average Height for each birth year and gender';
var height;
class bday gender;
format bday year4.;
run;

proc tabulate data=bday;
title '2a) TABULATE Average Height for each birth year';
var height;
class bday;
format bday yymmdd2.;
table bday='Year',
height*n height*mean;
run;

proc tabulate data=bday;
title '2b) TABULATE Average Height for each birth year and gender';
var height;
class bday gender;
format bday yymmdd2.;
table bday='Year' * gender,
height*n height*mean;
run;
[/pre]
Not applicable
Posts: 0