首页 > 解决方案 > SAS 人口统计表

问题描述

我一直在尝试创建一个像下面这样的人口统计表,但我似乎无法附加不同的表。请告知我可以在代码中进行调整的位置。

                Group A                           Group B          
       chort 1 cohort 2 cohort 3 subtotal cohort 4 cohort 5 cohort 6 subtotal
Age 
   n           
   mean
   sd
   median
   min
Gender
   n 
   female
   male
Race
   n 
   white 
   asian
   hispanic 
   black 

我的代码:

PROC FORMAT;
value content
  1=' '
  2='Age'
  3='Gender'
  4='Race'
value sex
  1='  n'
  2='  female'
  3='  male';
value race 
  1='  n'
  2='  white'
  3='  asian'
  4='  hispanic'
  5='  black';
value stat
  1='  n'
  2='  Mean'
  3='  Std. Dev.'
  4='  Median'
  5='  Minimum'; 
RUN;

DATA testtest; 
    SET test.test(keep = id group cohort age gender race); 
RUN; 

data tottest;
    set testtest;
    output;
    if prxmatch('m/COHORT 1|COHORT 2|COHORT 3/oi', cohort) then do;
        cohort='Subtotal';
        output;
    end;
    if prxmatch('m/COHORT 4|COHORT 5|COHORT 6/oi', cohort) then do;
        cohort='Subtotal';
        output;
    end;
run;

data count;
    if 0 then set testtest nobs=npats;
    call symput('npats',put(npats,1.));
    stop;
run;

proc freq data=tottest;
    tables cohort /out=patk0 noprint;
    tables cohort*sex /out=sex0 noprint;
    tables cohort*race /out=race0 noprint;
run;

PROC MEANS DATA = testtest n mean std min median; 
    class cohort; 
    VAR age; 
RUN; 

我知道我必须将其转置并在报告中输出。但在我这样做之前,我如何从我的 proc 方法、proc freq 等中获取变量?

标签: sastabular

解决方案


推荐阅读