"for those who purchased both, determine the time lag between the purchase of beer and diapers"
What would be the time lag for the following case? Or would there be several time lags?
1234 F beer Nov 1, 2008
1234 F diapers Nov 24, 2008
1234 M beer Nov 17, 2008
1234 M pencils Nov 30, 2008
1234 F diapers Dec 1, 2008
1234 F beer Dec 24, 2008
For the other 3 requirements:
data have;
infile datalines truncover;
input id sex:$1. product:$8. purch_dt anydtdte12.;
format purch_dt date9.;
datalines;
1234 F beer Nov 1, 2008
1234 F diapers Nov 24, 2008
5678 M beer Nov 17, 2008
5678 M pencils Nov 30, 2008
;
data want;
set have;
by id;
retain flag '00';
select (product);
when ('beer') substr(flag,1,1)='1';
when ('diapers') substr(flag,2,1)='1';
otherwise;
end;
if last.id then
do;
output;
flag='00';
end;
run;
proc format;
value $flag
'00' = 'No Beer / No Diapers'
'10' = 'Beer / No Diapers'
'01' = 'No Beer / Diapers'
'11' = 'Beer / Diapers'
;
run;
proc tabulate data=want;
class sex flag;
format flag $flag.;
keylabel all='Total' n=' ';
table sex='Gender' all,(flag='Products Purchased' all)*f=best12.
;
run;
HTH
Patrick
Message was edited by: Patrick