data aa;
libname Hn11_24R 'D:\SAS\HN11_24RC';
set Hn11_24R.Hn11_24RC(keep=id age n_fcode3 nf_intk3);
if age<=2 then age_g=1;
else if age<=6 then age_g=2;
else if age<=12 then age_g=3;
else if age<=19 then age_g=4;
else if age<=29 then age_g=5;
else if age<=49 then age_g=6;
else if age<=64 then age_g=7;
else age_g=8;
run;
proc sql;
create table aa01 as
select distinct id, age, age_g
from aa
order by id
;
create table aa02 as
select distinct id, count(id) as cnt, age, age_g, sum(nf_intk3) as nf_intk3_s
from aa
where N_fcode3 in ('11031')
group by id
order by id
;
create table aa03 as
select a.id, a.age, a.age_g, nf_intk3_s
from aa01 a full join aa02 b on a.id=b.id
;
quit;
data aa03, set aa03, if nf_intk3_s=. then nf_intk3_s=0 run;
options ls=150;
proc means data=aa02 n mean std max min p95 p99; class age_g; var nf_intk3_s; run;
proc means data=aa03 n mean std max min p95 p99; class age_g; var nf_intk3_s; run;
options;