Google


Wednesday, August 15, 2012

simple cross purchase code

If you have an item level data set and you want to explore cross purchase in SAS you usually need to sum and transpose your data first in several steps. Here is a simple SQL within SAS example using the max and case functions writing this succinctly, it won't necessarily run faster though.

proc sql;
create table x as
select custid, max(case when prodid=y then 1 else 0 end) as prod1, max(case when prodid=z then 1 else 0 end) as prod2
from items
group by 1;
quit;

proc freq;
table prod1*prod2;
run;

No comments: