SAS Proc Freq display categories with counts

倖福魔咒の 提交于 2019-12-10 23:00:02

问题


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?


回答1:


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;


来源:https://stackoverflow.com/questions/33301001/sas-proc-freq-display-categories-with-counts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!