100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > SAS:Freq过程介绍

SAS:Freq过程介绍

时间:2024-03-07 08:41:33

相关推荐

SAS:Freq过程介绍

Freq过程介绍

原文地址:/proceedings/sugi31/252-31.pdf

转载请注明出处:/s/blog_5d3b177c0100b68k.html

原文没有提供数据,所以就在网上随便找了个数据进行测试,地址如下:/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频数百分比累积频数 累积百分比

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

f11146.8411146.84

m12653.16237100.00

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

proc freq data=Htwt;

tables sex;

run;

结果如上。

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

proc format;

value height_ctg0-50= '<50'

50-60 = '50-60'

60-high= '>60';

value weight_ctg0-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 |

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

合计90147237

37.9762.03100.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

合计90147237

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

合计90147237

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

proc freq data=Htwt;

tables weight/norow nocol nopercent;

format weight weight_ctg.;

by sex;

run;

结果(以第一页为例)

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

FREQ 过程

weight

weight频数累积频数

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

<903838

90-1103573

>11053126

8 out:输出数据集

proc freq data=Htwt;

tables weight/ out=htwtfreq;

format weight weight_ctg.;

run;

proc print data= htwtfreq;

run;

结果:

ObsweightCOUNTPERCENT

1<907431.2236

290-1107832.9114

3>1108535.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;

结果:

ObsweightCOUNTPERCENT

11122610.9705

284208.4388

38172.9536

48572.9536

59272.9536

69472.9536

79572.9536

810572.9536

910872.9536

1011472.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;

结果:

ObssexweightCOUNTPERCENT

1m>1105322.3629

2m90-1103514.7679

3m<903816.0338

4f>1103213.5021

5f90-1104318.1435

6f<903615.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频数

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

Nonmissing237

height

height频数

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

Nonmissing237

weight

weight频数

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

Missing115

Nonmissing122

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。