zoukankan      html  css  js  c++  java
  • SAS的初级入门(五)

    1. SAS 中的 tabulate 的使用

    一般使用 tabulate 来制作报表 

    格式为:

    proc tabulate data = 数据集 选项;
    
    /* 使用 class 是用来分类的,变量名使用空格分开 */
    class 变量1 变量2 ...;
    
    /* var 跟着的是分析变量,即要分析计算的变量 */
    var 变量1 变量2 ...;
    
    /* 使用逗号分割,表达式一般使用 */
    table 页表达式,行表达式,列表达式;
    
    run;

    例子:

     1 data fly;
     2   input name $ gender $ jobcode $ salary;
     3   cards;
     4   a   male   computer  10000
     5   b   female  katydid  800
     6   c   male    fishman  3000
     7   d   female  katydid  900
     8   e   male    computer 8000
     9   f   female  katydid  1000
    10   g   male    fishman   5000
    11   h   female  katydid   2000
    12   i   male    fishman   2500
    13   j   female  katydid   9000
    14   z   male    computer  30000
    15 ;
    16 run;
    17 proc tabulate data=fly ;
    18   class  gender jobcode;
    19   var  salary;
    20   table gender*jobcode ,salary*mean;
    21   keylabel mean='平均值';
    22   label jobcode='Job Code'
    23         gender='Gender'
    24         salary='monthly salary';
    25   title 'Average Salary';
    26   footnote 'by zhao';
    27   run;

    注意:
    示例中的 * 表示交叉选项,选项可以是变量,也可以是函数,其中的 label 是标注的意思,对变量进行一个简单的标注,title 则是标题, footnote 则是脚注。

    结果:

    例子:

     1 proc format;
     2  value $city '1'='shenyang' '2'='anshan' '3'='fushun' '4'='benxi' '5'='yingkou' '6'='fuxin' '7'='liaoyang';
     3  value sex 1='male' 2='female';
     4  value nation 1='' 2='' 3='朝鲜' 4='' 5='其他';
     5 run;
     6 proc tabulate data=process.table order=formatted;
     7   format city $city. sex sex. nation nation. ;
     8   title 'city,poor,income';
     9   class city poo2 sex nation;
    10   footnote;
    11   var ave_inco;
    12   label city='Area';
    13   keylabel sum='Total';
    14   table nation;
    15   *table city,ave_inco;
    16   *table city,poo2*ave_inco*mean;
    17   *table city,poo2*ave_inco*(sum mean);
    18   *table city,poo2*pctn<poo2>;
    19   *table city,poo2*pctn<city>;
    20   *table city,poo2*pctn<city*poo2>;/*表格百分比*/
    21   *table city*poo2,ave_inco;
    22   *table city*poo2*(sum mean),ave_inco;
    23   *table sex,city poo2,nation*ave_inco*mean;
    24   *table (city ALL)*(poo2 all),ave_inco*mean;
    25 run;
  • 相关阅读:
    关于多工序生产中损耗的计算
    ERP相关术语
    linux下如何挂载U盘
    linux boot下的文件
    MPLS简述
    BGP
    linux添加新磁盘
    列表的方法
    python之列表
    python之模块初识-os模块
  • 原文地址:https://www.cnblogs.com/elkan/p/11009039.html
Copyright © 2011-2022 走看看