Chris The DBA
Chris The DBA

Reputation: 105

SAS Proc Freq display categories with counts

Wondering how this following can be done in base SAS. I've got the following code.

libname SASData  '/folders/myfolders/Datafiles';

data chap9ques6;
    set SASData.medical(keep=VisitDate);

    DayOfWeek = weekday(VisitDate);
run;

proc format;
    value Days 1='Sunday' 2='Monday' 3='Tuesday' 4='Wednesday' 5='Thursday' 6='Friday' 7='Saturday';
run;

proc freq data=chap9ques6;
    tables DayOfWeek /nocum nopercent missprint;

    Format DayOfWeek Days.;
run;

Which produces an acceptable result like this.

The FREQ Procedure

DayOfWeek Frequency

Sunday 1

Monday 1

Thursday 1

Friday 1

Saturday 2

when used with the sample SAS data. What I'd like to to is include the other weekdays in the list even though they don't have matching rows. "Tuesday 0 Wednesday 0"

How can I include those rows in the final output?

Upvotes: 2

Views: 749

Answers (1)

data _null_
data _null_

Reputation: 9109

You can use the DAYS format you created to supply the information on the "population" of days you want to report. PROC FREQ does not directly support the creation of something from nothing that can be done with PROC SUMMARY or PROC TABULATE. In this example I use PROC SUMMARY and PROC FREQ with WEIGHT statement and the ZEROS option.

data chap9ques6;
   DayOfWeek = 3;
   run;

proc format;
   value Days 1='Sunday' 2='Monday' 3='Tuesday' 4='Wednesday' 5='Thursday' 6='Friday' 7='Saturday';
   run;
proc summary data=chap9ques6 nway completetypes;
   class dayofweek / preloadfmt;
   format dayofweek days.;
   output out=counts;
   run;
proc print;
   run;

proc freq data=counts;
   tables DayOfWeek /nocum nopercent missprint;
   Format DayOfWeek Days.;
   weight _freq_ / zeros;
   run;

Upvotes: 3

Related Questions