通过示例学SAS(10)--制作表格

1.Tabulate过程根据一个或多个分类变量,产生包括频数,百分比,均值等统计描述信息的表格。

一个简单的产生表格的例子是

title "All Defaults with One CLASS Variable";
proc tabulate data=blood;
   class Gender;
   table Gender;
run;

class指明计算频数的类别变量,通常是字符型变量。table指明列在表格上的变量名,table后的变量名包含在必须在class指明的变量内。

制作串联表格

title "Demonstrating Concatenation";
proc tabulate data=learn.blood format=6.;
    class Gender BloodType;
    table Gender BloodType;
run;

blood的频数统计接在性别频数统计的后面。

在table中插入逗号后,将产生二维表达。

title "Demonstrating Table Dimensions";
proc tabulate data=learn.blood format=6.;
   class Gender BloodType;
   table Gender,
          BloodType;
run;

若指定变量名形式为variable1*variable2,则将变量2嵌套在变量1中产生表格。如

title "Demonstrating Nesting";
proc tabulate data=learn.blood format=6.;
       class Gender BloodType;
       table Gender * BloodType;
run;

对每一种性别,分别计算各种blood的频数。加入关键字ALL计算各变量的总频数。

2.对变量进行统计分析

proc tabulate也能计算变量的和或者平均值等统计量,并产生报告。例如

title "Specifying More than One Statistic";
proc tabulate data=learn.blood format=comma9.2;
    var RBC WBC;
    table (RBC WBC)*(mean min max);
run;

当然也可以结合class对变量进行分类统计。如

title "Combining CLASS and Analysis Variables";
proc tabulate data=learn.blood format=comma11.2;
   class Gender AgeGroup;
   var RBC WBC Chol;
   table (Gender ALL)*(AgeGroup All),
          (RBC WBC Chol)*mean;
run;

3.计算行和列的百分比

结合clss ,计算各分类变量的频数和百分比。例如

title "Counts and Percentages";
proc tabulate data=learn.blood format=6.;
    class BloodType;
    table BloodType*(n pctn);
run;

关键字colpctn和rowpctn分别计算列和行百分比。若需计算行百分比,则加上关键字colpctn。

title "Percents on Column Dimension";
proc tabulate data=learn.blood noseps;
    class Gender BloodType;
    table (BloodType ALL='All Blood Types'),
            (Gender ALL)*(n*f=5. colpctn*f=pctfmt7.1) /RTS=25;
     keylabel All = 'Both Genders'
                  n = 'Count'
                  colpctn = 'Percent';
run;

另外一种需要计算百分比的是数字变量。使用关键字Pctsum.例如

title "Computing Percentages on a Numerical Value";
proc tabulate data=learn.sales;
  class Region;
  var TotalSales;
  table (Region ALL),
          TotalSales*(n*f=6. sum*f=dollar8.
                          pctsum*f=pctfmt7.);
  keylabel ALL = 'All Regions'
                 n = 'Number of Sales'
              sum = 'Average'
            pctsum = 'Percent';
  label TotalSales = 'Total Sales';
run;

如果以class指定了分类变量,则可以分别以colpctsum和rowpctsum统计列百分比和行百分比。

4.理解缺失值

注意:在class后指定的分类变量里,如果有一个观测值里含有缺失值,则此观测值会被从表格里除去。也就是说,不被统计在表格里面。

为了将缺失值也统计进去,加入关键字missing。例如

title "The Effect of Missing Values on CLASS variables";
proc tabulate data=learn.missing format=4. missing;
   class A B;
   table A ALL,B ALL;
run;

缺失值会另外作为一种类别,列在表格里。

转载于:https://www.cnblogs.com/zgw21cn/archive/2008/08/22/1274220.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值