#### Average ___ per distinct observation in sas?

`````` Name:     Grade:      Subject:
Bob         8         English
Bob         6         Maths
Bill        7         English
Joe         9         Maths
``````

`````` Name:     Grade:
Bob         14
Bill        7
Joe         9
``````

4 个回复

``````/*sorting*/
proc sort data=have out=have1;
by name;
run;

do until(last.name);
by name;
end;
run;
``````

``````proc sql;
create table want as
from have
group by name;
``````

``````proc sort data=sashelp.class out=class(keep=Sex Name Weight);
by sex;
run;
``````

``````data res;
set class;
by sex;
retain sum 0 n 0;
sum+Weight;
n+1;

if last.sex then
do;
avg=sum/n;
n=0;
Sum=0;
end;
run;
``````

``````+---------+-----+--------+-------+---+--------------+
|  Name   | Sex | Weight |  sum  | n |     avg      |
+---------+-----+--------+-------+---+--------------+
| Alice   | F   |     84 |    84 | 1 |            . |
| Barbara | F   |     98 |   182 | 2 |            . |
| Carol   | F   |  102.5 | 284.5 | 3 |            . |
| Jane    | F   |   84.5 |   369 | 4 |            . |
| Janet   | F   |  112.5 | 481.5 | 5 |            . |
| Joyce   | F   |   50.5 |   532 | 6 |            . |
| Judy    | F   |     90 |   622 | 7 |            . |
| Louise  | F   |     77 |   699 | 8 |            . |
| Mary    | F   |    112 |     0 | 0 | 90.111111111 |
| Alfred  | M   |  112.5 | 112.5 | 1 |            . |
| Henry   | M   |  102.5 |   215 | 2 |            . |
| James   | M   |     83 |   298 | 3 |            . |
| Jeffrey | M   |     84 |   382 | 4 |            . |
| John    | M   |   99.5 | 481.5 | 5 |            . |
| Philip  | M   |    150 | 631.5 | 6 |            . |
| Robert  | M   |    128 | 759.5 | 7 |            . |
| Ronald  | M   |    133 | 892.5 | 8 |            . |
| Thomas  | M   |     85 | 977.5 | 9 |            . |
| William | M   |    112 |     0 | 0 |       108.95 |
+---------+-----+--------+-------+---+--------------+
``````

``````proc sql noprint;
from have
group by Name
;
quit;
``````

1. 在PROC MEANS语句上，有几个选项：
• NWAY-仅包括最高级别，否则SAS也将添加总体总计
• N / MEAN / NMISS / MEDIAN-要准备的统计数据
• STACKODS更改输出格式，这通常是大多数人想要的格式。
2. CLASS->分组变量
3. VAR->要分析的变量
4. ODS OUTPUT->将结果发送到名为WANT的表。

` `proc means data=sashelp.class NWAY N MEAN NMISS MEDIAN STACKODS; CLASS sex; *this is your grouping variable(s), ie name; VAR height; *this is the variable(s) you want to summarize; ods output summary = want; run;` `
1 在Sas中每个观察每月计数变量

2010-04-05 16:12:04 1 2743   sas
2 SAS：计算平均值，不包括当前观察值

4 计算每个观察的加权平均值 (Stata)

2021-02-17 22:01:09 1 124   stata
6 SAS中每个变量的平均行数

2017-10-09 17:11:47 1 39   sas/ proc
7 DAX：每日平均值

2018-10-11 07:46:23 1 1756   dax
8 重命名SAS中的重复观察

2016-02-03 20:17:12 2 406   sas
9 SAS特定的观察格式

2013-08-20 09:58:12 1 108   sas
10 SAS：单个观测值的AVG（）

2013-08-22 11:42:36 3 217   sql/ sas