@CathyVI wrote:
This is the overall goal am trying to get.
Event1
only
Event2 only
Case32 only
Event46 A
only
Event46 B
only
Event46 C
Only
Multiple
Total
30 days
31-60 days
Total
This looks like a two-way frequency table, so we need to create a second variable, let's call it Duration, in addition to event_type. Then we can use PROC FREQ to obtain such a table (which, in turn, could be used as a basis for a more sophisticated report).
Let me first create a more comprehensive sample dataset which includes all possible combinations of events and duration values (that have been mentioned so far).
/* Create a comprehensive sample dataset */
data have;
call streaminit(31415927);
do Event1=0 to 2;
do Event2=0 to 2;
do Case32=0 to 2;
do Event46=0 to 2;
if Event46 then do grp='A', 'B', 'C';
do _n_=1 to rand('integer',9);
output;
end;
end;
else do;
grp=' ';
do _n_=1 to rand('integer',9);
output;
end;
end;
end;
end;
end;
end;
run;
/* Define a format for variable Duration */
proc format;
value days
1=' <=30 days'
2='31-60 days';
run;
/* Create the analysis dataset */
data want(drop=_:);
set have;
array e[*] event1 event2 case32 event46;
length _s $4 _v event_type $40;
_s=cat(of e[*]);
_n0=countc(_s,'0');
if _n0=3 then do; /* Three zeros indicate that only one type of event has occurred. */
_vn=verify(_s,'0'); /* This determines which type of event it was. */
_v=vname(e[_vn]);
event_type=catx(' ',_v,grp,'only');
if _vn<3 then event_type=' '||event_type; /* Indentation improves sort order of report columns. */
Duration=e[_vn];
end;
else if _n0<3 then do; /* Fewer than 3 zeros indicate that multiple types of events have occurred. */
event_type='Multiple';
Duration=1+(countc(_s,'2')>1); /* Duration=2 only in case of multiple occurrences of value 2. */
end;
format Duration days.;
run;
/* Generate a simple report */
proc freq data=want order=formatted;
tables duration*event_type / nopercent norow nocol;
run;
Result:
The six missing values are from observations with Event1=Event2=Case32=Event46=0. The value of Duration for event_type='Multiple' is determined according to your specification
"if you have 2 in more than one group you will be multi_60."
... View more