DATA tmp;
INPUT FID$4. YEAR 8.;
CARDS;
1111 1988
1111 1987
1112 1955
1112 1961
1112 1948
1112 1987
1113 1988
1114 1955
1114 1985
1115 1973
1115 1977
1115 1998
1115 2003
;
RUN;
/*用于值映射,减少if else 代码*/
proc format;
value ftyear low-<1949='c'
1949-<2000='a'
2000-high='o'
;
run;
/*计算频数,可避免过多的 count语句*/
proc freq data=tmp;
table fid*year/out=tmp_1 noprint;
format year ftyear.;
run;
/*按照输出表格样式输出,把纵向的值,变为横向*/
proc transpose data=tmp_1 out=tmp_2(drop=_NAME_ _label_) /*PREFIX=cs_*/;
id year;
var count;
by fid;
idlabel year;
run;
/*把本身确实的,变为0*/
data tmp_3;
set tmp_2;
array _num_ _numeric_;
do i=1 to dim(_num_);
if _num_{i}=. then
_num_{i}=0;
end;
drop i;
run;