Proc Freq:Freq过程介绍_szdbl的博客-程序员宅基地

技术标签: SAS  

原文地址:Proc Freq:Freq过程介绍 作者: supersasmacro

 

Freq过程介绍

 

原文地址:http://www2.sas.com/proceedings/sugi31/252-31.pdf

转载请注明出处: http://blog.sina.com.cn/s/blog_5d3b177c0100b68k.html

原文没有提供数据,所以就在网上随便找了个数据进行测试,地址如下:http://www.sasenterpriseminer.com/data/htwt.xls

该数据包含4个变量(性别sex,年龄age,身高height,体重weight),共237个观测。

 

1 Freq 语法

proc freq <options> ; 

by variables ; 

exact statistic-options < / computation-options> ; 

output <OUT= dataset> options ; 

tables requests < /options> ; 

test options ;   

weight variable ; 

 

 

2 如果直接运行freq过程步,程序如下,它将会对所有的变量进行操作。

proc freq data=Htwt;

run;

部分结果:

FREQ 过程

sex

sex      频数      百分比     累积频数 累积百分比

------------------------------------------------------------------------------

          111     46.84          111     46.84

          126     53.16          237    100.00

 

3 tables:得到给定变量的频数统计,或多变量的交叉表频数统计。

proc freq data=Htwt;

tables sex;

run;

结果如上。

 

4 format:对连续数值变量做Freq时,系统会对每个数值进行频数统计,这个结果一般不是我们所需要的。我们一般会将连续变量转换为离散变量,这个可以通过Format过程步来实现。

proc format;

value height_ctg    0-50   = '<50'

   50-60 = '50-60'

   60-high   = '>60';

value weight_ctg     0-90    = '<90'

   90-110 = '90-110'

   110-high     = '>110';

 run;

 

proc freq data=Htwt;

tables weight*height;

format weight weight_ctg.;

format height height_ctg.;

run;

结果:

FREQ 过程

 

weight * height 表

weight(weight)     height(height)

 

频数    |

百分比  |

行百分比|

列百分比|50-60   |>60      合计

--------+--------+--------+

<90        61 |     13 |     74

        25.74 |   5.49 |  31.22

   82.43 |  17.57 |

        67.78 |   8.84 |

--------+--------+--------+

90-110     24 |     54 |     78

        10.13 |  22.78 |  32.91

        30.77 |  69.23 |

        26.67 |  36.73 |

--------+--------+--------+

>110        5 |     80 |     85

         2.11 |  33.76 |  35.86

        5.88 |  94.12 |

     5.56 |  54.42 |

--------+--------+--------+

合计          90      147      237

37.97    62.03   100.00

 

5 norow nocol nopercent:有时我们只需要频数,不需要各行各列的百分比,我们就可以在tables后面加上这些参数。

 

proc freq data=Htwt;

tables weight*height/norow nocol nopercent;

format weight weight_ctg.;

format height height_ctg.;

run;

 

结果:

FREQ 过程

weight * height 表

weight(weight)     height(height)

 

频数    |50-60   |>60      合计

--------+--------+--------+

<90        61 |     13 |     74

--------+--------+--------+

90-110     24 |     54 |     78

--------+--------+--------+

>110        5 |     80 |     85

合计          90      147      237

 

Norow:不要行的百分比

Nocol:不要列的百分比

Nopercent:不要频数的百分比

Nocum:单变量时不要累积频数和累积百分比

Nofreq:不要频数

Noprint:不打印

Nowarn:不输出警告信息

Missing:将缺失值也进行统计

 

6 对变量加label标识,使输出更直观

proc freq data=Htwt;

tables weight*height/norow nocol nopercent;

format weight weight_ctg.;

format height height_ctg.;

label weight = '高度';

label height = '重量';

run;

结果:

FREQ 过程

weight * height 表

 

weight(高度)     height(重量)

频数    |50-60   |>60      合计

--------+--------+--------+

<90        61 |     13 |     74

--------+--------+--------+

90-110     24 |     54 |     78

--------+--------+--------+

>110        5 |     80 |     85

合计          90      147      237

 

7 By:对这个变量的值进行分页显示

proc freq data=Htwt;

tables weight/norow nocol nopercent;

format weight weight_ctg.;

by sex;

run;

结果(以第一页为例)

----------------- sex=m ------------

 FREQ 过程

 weight

 

 weight      频数        累积频数

 ------------------------------

 <90             38          38

 90-110          35          73

 >110            53         126

 

8 out:输出数据集

proc freq data=Htwt;

tables weight/ out=htwtfreq;

format weight weight_ctg.;

run;

proc print data= htwtfreq;

run;

结果:

Obs    weight    COUNT    PERCENT

 

    <90         74     31.2236

    90-110      78     32.9114

    >110        85     35.8650

 

9 order选项:使输出按指定的order方式排序。

Order=data :按输入数据集的顺序排序

Order=formatted :按其formatted value排序

Order=freq :按计算的频数的降序排序

Order=internal :按其unformatted value排序

 

data htwttmp;

set htwt;

weight=round(weight);

run;

 

proc freq data=Htwttmp order=freq;

tables weight/ out=htwtfreq ;

run;

 

proc print data= htwtfreq(obs=10);

run;

结果:

Obs    weight    COUNT    PERCENT

 

      112       26     10.9705

       84       20      8.4388

       81            2.9536

       85            2.9536

       92            2.9536

       94            2.9536

       95            2.9536

      105            2.9536

      108            2.9536

 10      114            2.9536

 

10 list当对多个变量进行交叉频率操作,我们只需要频数和百分比时可以用到。

proc freq data=Htwttmp order=freq;

tables sex*weight/list out=htwtfreq ;

format weight weight_ctg.;

run;

 

proc print data= htwtfreq(obs=10);

run;

结果:

Obs    sex    weight    COUNT    PERCENT

 

         >110        53     22.3629

         90-110      35     14.7679

         <90         38     16.0338

         >110        32     13.5021

         90-110      43     18.1435

         <90         36     15.1899

 

11 对缺失值和非缺失值进行频数统计

 

data Htwtmissing;

set Htwttmp;

if weight<100 then weight=.;

run;

proc format;

   value misscnt .= 'Missing'

               other ='Nonmissing';

run;

proc freq data = Htwtmissing;

   tables _numeric_ / missing nocum nopercent;

   format _numeric_ misscnt.;

run;

 

结果:

age

 age      频数

 ----------------------

 Nonmissing         237

 

 height

 height      频数

 ----------------------

 Nonmissing         237

 

 weight

 weight      频数

 ----------------------

 Missing            115

 Nonmissing         122

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/szdbl/article/details/48547567

智能推荐

旋转魔方阵 动态开辟二维数组 程序设计作业_算法矩阵123894765_Feixue0124的博客-程序员宅基地

【问题描述】输入一个自然数N(N属于2到15),要求输出如下的魔方阵,即边长为NN,元素取值为1至NN,1在左上角,呈顺时针方向依次放置各元素。N=3时:1 2 38 9 47 6 5【输入形式】从标准输入读取一个整数N。【输出形式】向标准输出打印结果。输出符合要求的方阵,每个数字占5个字符宽度,向右对齐,在每一行末均输出一个回车符。【输入样..._算法矩阵123894765

微信小程序跳转页面刷新内容-程序员宅基地

@微信小程序微信小程序的跳转tabar刷新页面新手到来 还请多多指教 url: '../find/find', //跳转页面tabar以及跳转页面的刷新 success() { var page = getCurrentPages().pop(); if (page == undefined || page == null) return;

翻转字符串里的单词(java) LeetCode第151题_leetcode 151 java-程序员宅基地

一、题目描述给定一个字符串,逐个翻转字符串中的每个单词。示例 1:输入: "the sky is blue"输出:"blue is sky the"示例 2:输入: " hello world! "输出:"world! hello"解释: 输入字符串可以在前面或者后面包含多余的空格,但是反转后的字符不能包括。示例 3:输入: "a good ..._leetcode 151 java

Android studio-设置创建类时,添加作者名和日期等_android studio创建类作者_tlfclwx的博客-程序员宅基地

设置创建类时,添加作者名和日期等步骤:File -> Setting-> Editor -> File and Code Templates 选项,点击 Includes -> File Header一般的格式是下面这种,也可自己根据格式添加想要的内容/** * @Author tlfclwx * @Date ${Date} ${TIME} */..._android studio创建类作者

tar解压出错:gzip: stdin: unexpected end of file的解决_活着1989的博客-程序员宅基地

今天下载了一个Linux内核文件,解压的时候出现了这样的错误:gzip: stdin: unexpected end of filetar: Unexpected EOF in archivetar: Unexpected EOF in archivetar: Error is not recoverable: exiting now开始想不明白,最后发现是压缩包有问题,本...

随便推点

第六篇:MySQL之事务_mysql事务会覆盖前一个事务吗_张孟浩_jay的博客-程序员宅基地

事务的概念事务是数据库的最小的操作单元,要么全部执行,要么都不执行。事务是MySQL中存储引擎方面支持的功能。MySQL支持多引擎,但是不是所有的引擎都支持事务,MyISAM不支持事务,InnoDB支持事务。事务的特征1、原子性事务中的操作要么完全执行,要么都不执行2、持久性事务提交后的数据要能够持久保存,即使系统故障数据也不会丢失。3、隔离性并发事务之间需要有一定的隔离性,防止数据的不一致。4、一致性事务执行前后,数据前后要保持一致。原子性事务的原子性,InnoDB是通过undol_mysql事务会覆盖前一个事务吗

qt 在windows下环境的搭建_win10如何安装qt-everywhere-src_伊娃2015的博客-程序员宅基地

1.VS2005已经是完事了,还有sp1什么的。2.所需下载的东西qt-everywhere-opensource-src-4.8.4.zip(当然你也可以下载其他的版本) qt-vs-addin-1.1.11-opensource.exe(qt在VS2005中的插件) qt-win-opensource-4.6.3-vs20_win10如何安装qt-everywhere-src

ESRGAN - Enhanced Super-Resolution Generative Adversarial Networks论文翻译——中英文对照_srgan论文翻译_SnailTyan的博客-程序员宅基地

文章作者:Tyan博客:noahsnail.com | CSDN | 简书声明:作者翻译论文仅为学习,如有侵权请联系作者删除博文,谢谢!翻译论文汇总:https://github.com/SnailTyan/deep-learning-papers-translationESRGAN: Enhanced Super-Resolution Generative Adversarial NetworksAbstractThe Super-Resolut_srgan论文翻译

数电与模电的根本区别 转_数电模电_GoodShot的博客-程序员宅基地

要回答这个问题,首先要弄清数电与模电的根本区别到底在哪。1)、个人认为,在应用上两者之间最主要的差别是两者的工作逻辑不同。一般来说,数字电路设计做好数字逻辑就差不多了,----剩下和问题就交给模拟去办了。打个比方说,一个纯粹的数字电路设计完成,就是逻辑设计的完成,或者说,_数电模电

推荐文章

热门文章

相关标签