Pregunta

We have a problem with people not submitting hospital visit information in a timely manner. I'm trying to decipher how long (on average) after a visit date a hospital will submit information for all the visits that occured on that date.

Trying to create a table from a current dataset which has 3 relevant fields: Unique_Visiting_ID, Visit_Date, Date_Created, Chief_Complaint.

There can be multiple rows with the same unique_visiting_ID, the unique_visiting_id is the unique identifier for a single patient visit. Visit_date is the date of the visit. The date_created variable tell us the date a a row was sent to us.

The columns on the table I'd like to create are: Days after Visit (0-14) and average number of visits reported on a specific date

For the second column, I'd like to know: if I'm limiting date created to 0 days after a visit_date, how many visits (with non-null chief_complaint) occured on a visit date?

if I'm limiting date created to 0 or 1 days after a visit_date, how many visits (with non-null chief_complaint) occured on a visit date?

if I'm limiting date_created to 0, 1 or 2 days after a visit_date, how many visits (with non-null chief_complaint)occurred on that visit date?

etc etc until you get to 1-14 days after a visit_date.

Any ideas? I started off with this, which I know is wrong, but not sure how to fix it...

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top