网格单元格的 SAS 点数
SAS Point counts for grid cells
我正在做一个 class 项目,但碰壁了。这个想法似乎很简单,但我似乎无法开始。我们得到了一个包含 300 个 x 和 y 数据点的数据集。将数据加载到 SAS 并 运行 在数据上绘制散点图后,我们被指示连接 SAS 代码以计算每个网格单元的点。像 (1,1) 有 5 个数据点。最终产品应该是 table,其计数类似于:
0, 0, 0, 0, 0, 0, 0,
0, 2, 3, 0, 0, 0, 1,
1, 3, 0, 5, 9, 0, 2,
抱歉,我不够酷,无法 post 图片。
我相信这是一个简单的请求,但我还没有找到答案。通过 COUNT、FREQ 和 TABULATE 的变体,我有 运行。非常感谢您的帮助。
出于报告目的:
TABULATE
使用 X
和 Y
作为 CLASS
变量。您将能够 table x
和 y
组合(即坐标)计数。
REPORT
使用 Y
作为 ACROSS
变量。
出于数据目的:
FREQ
后跟 TRANSPOSE
。但是生成的数据形式不是很有用。
示例:
data have;
call streaminit(2020115);
do _n_ = 1 to 300;
x = rand('integer',0,5);
y = rand('integer',0,5);
output;
end;
run;
ods html file='tabulate.html';
proc tabulate data=have;
class x y;
table x,y / nocellmerge;
run;
proc report data=have;
columns x y;
define x / group;
define y / across;
run;
proc freq noprint data=have;
table x * y / out=counts(keep=x y count);
run;
proc transpose data=counts out=wider_not_better(drop=_name_ _label_) prefix=y_count_for_;
by x;
id y;
var count;
format _0 _1 _2 _3 _4 _5 6.;
run;
proc print data=wider_not_better;
run;
ods html close;
将产生如下输出
我正在做一个 class 项目,但碰壁了。这个想法似乎很简单,但我似乎无法开始。我们得到了一个包含 300 个 x 和 y 数据点的数据集。将数据加载到 SAS 并 运行 在数据上绘制散点图后,我们被指示连接 SAS 代码以计算每个网格单元的点。像 (1,1) 有 5 个数据点。最终产品应该是 table,其计数类似于:
0, 0, 0, 0, 0, 0, 0,
0, 2, 3, 0, 0, 0, 1,
1, 3, 0, 5, 9, 0, 2,
抱歉,我不够酷,无法 post 图片。
我相信这是一个简单的请求,但我还没有找到答案。通过 COUNT、FREQ 和 TABULATE 的变体,我有 运行。非常感谢您的帮助。
出于报告目的:
TABULATE
使用X
和Y
作为CLASS
变量。您将能够 tablex
和y
组合(即坐标)计数。REPORT
使用Y
作为ACROSS
变量。
出于数据目的:
FREQ
后跟TRANSPOSE
。但是生成的数据形式不是很有用。
示例:
data have;
call streaminit(2020115);
do _n_ = 1 to 300;
x = rand('integer',0,5);
y = rand('integer',0,5);
output;
end;
run;
ods html file='tabulate.html';
proc tabulate data=have;
class x y;
table x,y / nocellmerge;
run;
proc report data=have;
columns x y;
define x / group;
define y / across;
run;
proc freq noprint data=have;
table x * y / out=counts(keep=x y count);
run;
proc transpose data=counts out=wider_not_better(drop=_name_ _label_) prefix=y_count_for_;
by x;
id y;
var count;
format _0 _1 _2 _3 _4 _5 6.;
run;
proc print data=wider_not_better;
run;
ods html close;
将产生如下输出