tj0412ymy 发表于 2011-8-12 18:42 
时间所限,每列的最大值,次最大值...,可在PROC REPORT中标注不同的颜色,更美观一些,期待LXS解决!
data test;
input order_id $ product_id $;
cards;
1 A
1 B
1 D
2 A
2 B
3 A
3 C
3 E
3 F
4 A
4 B
5 A
5 B
5 C
5 D
5 F
5 G
;
run;
proc sql noprint;select count(distinct product_id) into:num from test;quit;
proc sql noprint;select distinct product_id into:pro1 - :pro%left(&num) from test order by product_id;quit;
options mprint symbolgen;
%macro test();
proc sql;
%do j=1 %to #
create table temp&j as
select
%do i=1 %to #
%if &i=&j %then %do;
. as &&pro&i,
%end;
%else %do;
sum(&&pro&i) as &&pro&i,
%end;
%end;
"&&pro&j" as pro
from
(select
%do k=1 %to #
sum(case when product_id="&&pro&k" then 1 else 0 end) as &&pro&k,
%end;
order_id from test
group by order_id)
where &&pro&j>0;
%end;
run;
data final;
set
%do i=1 %to #
temp&i
%end;
;run;
%mend;
%test();
随手写了一个,仅供参考。呵呵。