1
votes

I'm new to SAS so looking for advices/ideas here..

Essentially I want to create summary table/report containing number of observations, percentages of certain group and means.

Consider the following example:

A/C No   Status   DaysToStatus
1        Suspend  10
2        Blocked  20
3
4        Suspend  20

My intended output/report is something like:

Average Days To Suspend    Average Days to Blocked    % Suspend    %Blocked
15                         20                         50%          25%

I can do the average easily using Proc Report function but I am struggling to incorporate the observations and its percentages even with Compute function.

Any ideas on how I go about in doing this?

3

3 Answers

3
votes

You haven't posted your code, so approach might not be the same as yours. I don't think you need compute. Build your report with three columns: status (group), daystostatus mean, and the pctn statistic to count the rows. Use the missing option in the proc report statement to base the percentage on the total including those with a missing status.

proc report data=yourdata missing nowd;
  column status daystostatus pctn;
  define status / group;
  define daystostatus / analysis mean 'Avg days to status';
  define pctn / 'Pct of total' format=percent10.;
run;
1
votes

Preparing the data first

        data have;
        Number = 1;
        Status = 'Suspend';
        DaysToStatus = 10;
        output;
        Number = 2;
        Status = 'Blocked';
        DaysToStatus = 20;
        output;
        Number = 3;
        Status = '';
        DaysToStatus =.;
        output;
        Number = 4;
        Status = 'Suspend';
        DaysToStatus =20;
        output;
        run;

This should work for you:

            data want;
            set have end = eof;
            if Status='Suspend' then do;
                sum_suspend+DaysToStatus;
                count_suspend+1;
            end;
            else if status='Blocked' then do;
                sum_blocked+DaysToStatus;
                count_blocked+1;
            end;
            total_sum+DaysToStatus;
            total_count = _n_;
            Average_Days_To_Suspend = sum_suspend / count_suspend;
            Average_Days_To_blocked = sum_blocked / count_blocked;
            percent_suspend = count_suspend/total_count;
            percent_blocked = count_blocked/total_count;
            if eof;
            drop n status number DaysToStatus sum_: count_: total_:;
            run;
1
votes

proc sql;

select sum(case when status eq 'Suspend' then DaysToStatus else 0 end)/sum(case when status eq 'Suspend' then DaysToStatus else 0 end) as
avg_days_to_suspend,

sum(case when status eq 'Blocked' then DaysToStatus else 0 end)/ sum(case when status eq 'Blocked' then DaysToStatus else 0 end) as
avg_days_to_blocked,

sum(case when status eq 'Suspend' then DaysToStatus else 0
end)/sum(DaysToStatus) as percent_suspend format = percent7.0,

sum(case when status eq 'Blocked' then DaysToStatus else 0
end)/sum(DaysToStatus) as percent_blocked format = percent7.0

from work.in_ds; /* replace work.in_ds with your own data set */

quit;