1) how you get-0.26009 out of -2.1, 0.25, and 0.26?
2) do you want to get something like this:
data have;
input
ID Year Size $ Return ;
cards;
1 2016 sml -2.1
1 2017 sml 0.25
1 2018 med 0.26
2 1999 sml 0.5
2 2000 med -0.8
2 2001 med 0.7
2 2002 med 1.9
;
run;
proc sort data = have;
by ID year;
run;
data want;
set have;
by id;
if first.ID then _avg = .;
_avg + return;
_n + (return>.z);
if last.id then average = _avg/_n;
drop _:;
put _all_;
run;
proc print;
run;
data have;
input
ID Year Size $ Return ;
cards;
1 2016 sml -2.1
1 2017 sml 0.25
1 2018 med 0.26
2 1999 sml 0.5
2 2000 med -0.8
2 2001 med 0.7
2 2002 med 1.9
;
run;
proc sql;
create table temp as
select *,mean(return) as mean from have group by id;
quit;
data want ;
set temp;
by id;
if not last.id then call missing(mean);
run;
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.