楼主,是不是要求得到任意的城市、名称、情况的统计呢?
可以直接写一个macro,然后调用即可,本人用北京、a,然后以情况1为需要统计的column(当然可以选择其他的情况2、3,仅仅在调用的macro里面改个数字即可),假如需要其他数据,直接再调用几次macro,改一下参数即可,假如希望统计的结果在一个表上,那就merge一下即可。你看看下面的代码是不是你需要的?
data test;
input location $ type $ situ1 $ situ2 $ situ3 $;
datalines;
Beijing a z1 a1 s1
Beijing a z1 z1 s1
Beijing a s1 z1 a1
Beijing b c1 a1 b1
Beijing b a1 z1 b1
Shanghai a s1 z1 b1
;
run;
/*The following code is to calculate the number of z1 and s1 under the condition where location=Beijing and type=a*/
/*Adopt macro to facilitate programming*/
%macro cnt(n,var,loc=,tp=);
proc sql;
create table cnt&var as
select location,type,count(situ&n) as NumOf&var
from test
where location="&loc" and type="&tp" and situ&n="&var"
group by location,type,situ&n;
quit;
%mend;
/*Call macro cnt*/
%cnt(1,z1,loc=Beijing,tp=a) ;
%cnt(1,s1,loc=Beijing,tp=a) ;
/*Merge tables generated by macro cnt*/
data cb;
merge cnts1 cntz1;
run;
|