Help using Base SAS procedures

counting over time

Reply
N/A
Posts: 0

counting over time

Hi, I'm a new SAS user, and I could use some help. I would like to be able to look at frequency (or counts) over time. My data set has 80 days, and for each day, there is a value representing appointment attendance (e.g., attended, missed due to illness, missed due to holiday, etc.). My data looks like this:

ID typeday1 typeday2 typeday3 typeday4 .......up to typeday80
1 3 2 3 2
2 4 2 4 3

What I'd like to be able to do is:
a) find out, looking across all 80 days, how many appointments each person attended (e.g., 2s), how many did they miss due to holiday (e.g., 3), etc.
and
b) somehow looking across every person and every day overall, how many appointments were missed for each reason.

Any suggestions for how to accomplish this would be great.

Thanks!
Respected Advisor
Posts: 3,799

Re: counting over time

Posted in reply to deleted_user
I would tranpose tranpose the data to
[pre]
id day visitType
1-n 1-80 1-4
[/pre]

But here is code to work with the wide data.

[pre]
data typeday(drop=typeDaySmiley Happy;
array typeday[80];
infile cards missover;
input id:$3. typeday
  • ;
    array tCount[4];
    call missing(of tCount
  • );
    do _n_ = 1 to dim(typeday) while(not missing(typeday[_n_]));
    tCount[typeday[_n_]] + 1;
    end;
    TotalMissed = sum(of tcount2-tcount4); *2,3,4 are missed codes?;
    cards;
    1 3 2 3 2
    2 4 2 4 3
    ;;;;
    run;
    proc print;
    run;
    [/pre]
  • SAS Super FREQ
    Posts: 8,864

    Re: counting over time

    Posted in reply to deleted_user
    Hi:
    I wondered whether you might want a report... something like one of these:
    [pre]
    +------------------------------------------------------------------------+
    |Patient Visit Status| status | |
    | +--------------------------------------+ |
    | | Appt | | | |
    | | Attended |Miss Holiday|Miss Illness| All Types |
    +--------------------+------------+------------+------------+------------+
    |Patient | | | | |
    +--------------------+ | | | |
    |Alice | 2.00| 2.00| 0| 4.00|
    +--------------------+------------+------------+------------+------------+
    |Bob | 1.00| 1.00| 2.00| 4.00|
    +--------------------+------------+------------+------------+------------+
    |Carla | 3.00| 0| 1.00| 4.00|
    +--------------------+------------+------------+------------+------------+
    |Dan | 3.00| 1.00| 0| 4.00|
    +--------------------+------------+------------+------------+------------+
    |All Patients | 9.00| 4.00| 3.00| 16.00|
    +------------------------------------------------------------------------+

    or

    +------------------------------------------------------------------------+
    |Daily Visit Status | status | |
    | +--------------------------------------+ |
    | | Appt | | | |
    | | Attended |Miss Holiday|Miss Illness|All Patients|
    +--------------------+------------+------------+------------+------------+
    |Day | | | | |
    +--------------------+ | | | |
    |typeday1 | 1.00| 1.00| 2.00| 4.00|
    +--------------------+------------+------------+------------+------------+
    |typeday2 | 3.00| 1.00| 0| 4.00|
    +--------------------+------------+------------+------------+------------+
    |typeday3 | 2.00| 1.00| 1.00| 4.00|
    +--------------------+------------+------------+------------+------------+
    |typeday4 | 3.00| 1.00| 0| 4.00|
    +--------------------+------------+------------+------------+------------+
    |All Days | 9.00| 4.00| 3.00| 16.00|
    +------------------------------------------------------------------------+

    [/pre]

    These two reports are examples of what you can do with PROC TABULATE. If you keep the data "wide", so that all the info for one patient is on one obs, then your choice to count is to use array processing. If you use PROC TRANSPOSE to turn the wide data into long and skinny data, then other procedures open up to you for reporting.

    In addition, you can create user-defined formats, like the ones below, that would allow you to display a meaningful label, such as "Appt Attended" or "Miss Holiday" instead of codes 2 or 3. Or, formats could even be used to associate a name with an id.
    [pre]
    proc format;
    value typvis
    2='Appt Attended'
    3='Miss Holiday'
    4='Miss Illness';

    value PtID
    1 = 'Alice'
    2 = 'Bob'
    3 = 'Carla'
    4 = 'Dan';
    run;
    [/pre]

    What kind of report did you envision? Or were you interested in a data set?

    cynthia
    N/A
    Posts: 0

    Re: counting over time

    Posted in reply to deleted_user
    Thank you both so much for your help!

    Cynthia, I think for now I would like to keep the data wide and use an array like you suggested to count across appointment days. Because then I could use the "count" generated in other analyses. Do you have any suggestions of what such an array might look like?

    There are 10 appointment days, and on each day you could have any one of 5 outcomes (e.g., attended, missed because doctor cancelled, missed because sick, missed because holiday, missed for personal reasons).

    What I'd eventually like to be able to say is that across all participants and all appointment days, X% of appointments were attended, X% were missed because the doctor cancelled, etc.

    Thanks for your help, and hope that made sense!
    SAS Super FREQ
    Posts: 8,864

    Re: counting over time

    Posted in reply to deleted_user
    Hi:
    Well, there was an example of an array in data_null_'s post. For a beginner, sometimes working with Arrays can be challenging. This paper is a good introduction to Array processing:
    http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf

    There is an alternative, however, to using arrays.

    You can keep the data in whatever form you want -- you can keep it long and wide for storage and reference and data entry purposes. But then you can create temporary datasets to do all the countring.

    SAS has some perfectly wonderful procedures that do counts and percents --and-- if the data is in the right form, will give you ALL the information you want, either in report form or in dataset form.

    Without knowing how you need to use the counts in other analysis, it's hard to make a recommendation about whether arrays are best or whether looking at PROC TRANSPOSE and PROC FREQ are best. Generally, I recommend starting with TRANSPOSE and FREQ or TRANSPOSE and TABULATE for beginners -- because it is easier, sometimes to deal with a self-contained procedure that only does 1 thing than to jump into DATA step processing, where the syntax and the process can sometimes be challenging.

    cynthia
    N/A
    Posts: 0

    Re: counting over time

    Posted in reply to Cynthia_sas
    Thanks so much for your help! I'll try both your and data_null_'s suggestions when I get back to work on Tuesday. I really appreciate it!
    Ask a Question
    Discussion stats
    • 5 replies
    • 123 views
    • 0 likes
    • 3 in conversation