Since you didn't post what output you need. So it is hard to make sure what your intention is . data have;
input ID_NO TRANS_DATE :mmddyy10. PRODUCTS $ NAME $ STATE $;
datalines;
255 3/2/2012 BED JOHN NY
255 3/2/2012 PILLOW JOHN NY
255 3/2/2012 MATTRES JOHN NY
468 9/12/2012 BED MIKE California
468 9/12/2012 PILLOW MIKE MARYLAND
468 9/12/2012 MATTRES MIKE California
137 6/25/2012 BED JIM Michigan
137 6/25/2012 PILLOW JIM MARYLAND
137 6/25/2012 MATTRES TOM Michigan
137 6/25/2012 MATTRES JIM Michigan
;
run;
proc sql;
title "Pct deviate name";
select b.*, n_name/n as pctName format=percent8.2
from (select id_no,trans_date,count(*) as n from have group by id_no,trans_date) as a,
(select id_no,trans_date,name,count(*) as n_name from have group by id_no, trans_date,name) as b
where a.id_no=b.id_no and a.trans_date=b.trans_date ;
title "Pct deviate state";
select b.*, n_STATE/n as pctSTATE format=percent8.2
from (select id_no,trans_date,count(*) as n from have group by id_no,trans_date) as a,
(select id_no,trans_date,STATE,count(*) as n_STATE from have group by id_no, trans_date,STATE) as b
where a.id_no=b.id_no and a.trans_date=b.trans_date ;
quit;
Ksharp
... View more