- /************************************1. 每个id一共买了几种商品*/
- proc sql;
- create table want1 as
- select distinct x, sum(n) as count from (select *,1 as n from x)
- group by x;
- quit;
- /************************************2. 不同商品组合的购买频数*/
- proc sort data=x;
- by x y;
- run;
- proc transpose data=x
- out=x1(drop=_name_);
- var y;
- id y;
- by x;
- run;
- /*商品共有哪几种*/
- proc sql;
- create table product as
- select distinct y
- from x;
- quit;
- /*生成宏变量product,最后一步group by需要使用。特别适用于当商品种类多时*/
- proc sql;
- select y into: groupby separated by ", "
- from product;
- quit;
- proc sql;
- create table want2(drop=n) as
- select distinct *,sum(n) as count
- from (select *,1 as n from x1(drop=x))
- group by &groupby;
- quit;


雷达卡




京公网安备 11010802022788号







