As I understand it, you really want to produce two tables:
A list of all visits, with number of days until submission/creation for each
A list of all dates, with number of visits per date, including how many were submitted 0-14 days after
If that is what you meant, this macro should do the trick. dsn_in
is the name of your original dataset. dsn_out_days
is the name of the dataset holding the results for the first bullet point. dsn_out_summary
is the name of the dataset holding the results for the second bullet point.
%MACRO do_analysis (dsn_in = , dsn_out_days = , dsn_visits_by_date = );
%LOCAL i ;
DATA &dsn_out_days;
SET &dsn_in;
days_after_visit = INTCK ('DAYS', Visit_Date, Date_Created);
%DO i = 0 %TO 14;
submitted_up_to_&i._days_after = (days_after_visit <= &i);
LABEL submitted_up_to_&i._days_after = "Submitted Up To &i Days After" ;
%END;
RUN;
PROC SUMMARY NWAY DATA = &dsn_out_days (
WHERE = ( NOT MISSING (Chief_Complaint) )
);
CLASS Visit_Date;
OUTPUT
OUT = &dsn_visits_by_date (
DROP = _TYPE_
RENAME = (_FREQ_ = total_visits)
)
SUM (
%DO i = 0 %TO 14;
submitted_up_to_&i._days_after
%END;
) =
;
RUN;
/* Comment out this data step to see how everything works under the hood */
DATA &dsn_out_days;
SET &dsn_out_days (
DROP =
%DO i = 0 %TO 14;
submitted_up_to_&i._days_after
%END;
);
RUN;
DATA &dsn_visits_by_date;
SET &dsn_visits_by_date ;
LABEL total_visits = "Total Visits";
RUN;
PROC SORT DATA = &dsn_visits_by_date ;
BY Visit_Date ;
RUN;
%MEND;
Note that the %DO
macro usage is there to cut down on the drudgery of typing:
submitted_up_to_1_days_after = (days_after_visit <= 1);
submitted_up_to_2_days_after = (days_after_visit <= 2);
submitted_up_to_3_days_after = (days_after_visit <= 3);
. . . .
But if you prefer a macro-free solution I can edit. Just let me know.