Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在sas中创建一个表,以查看列变量相对于其他列的计数?_Sas_Dataset - Fatal编程技术网

如何在sas中创建一个表,以查看列变量相对于其他列的计数?

如何在sas中创建一个表,以查看列变量相对于其他列的计数?,sas,dataset,Sas,Dataset,我的数据集如下: id a b 1 1 1 2 3 4 3 1 0 4 2 3 其中a和b有值(0-4)。我想创建如下视图: a/b 0 1 2 3 4 0 3 5 0 0 0 1 4 4 0 0 0 2 2 3 0 0 6 基本上,我想得到a相对于b的计数。如何在sas中创建视图?为了完整起见,您可以使用Proc tablate和CLASSDATA选项显示计数 例如: data have; call streaminit(123); do id = 1 to 1

我的数据集如下:

id a b
1  1 1
2  3 4
3  1 0
4  2 3
其中a和b有值(0-4)。我想创建如下视图:

a/b 0 1 2 3 4
0   3 5 0 0 0
1   4 4 0 0 0
2   2 3 0 0 6

基本上,我想得到a相对于b的计数。如何在sas中创建视图?

为了完整起见,您可以使用
Proc tablate
CLASSDATA
选项显示计数

例如:

data have;
  call streaminit(123);
  do id = 1 to 1000;
    a = rand('integer',0,4);
    do until (b ne 3);
      b = rand('integer',0,4);
    end;

    output;
  end;
run;

data allpairs;
  do a = 0 to 4;
  do b = 0 to 4;
    output;
  end;
  end;
run;

ods html file='output.html' style=plateau;

options missing = '0';

proc tabulate data=have classdata=allpairs;
  class a b;
  table a=' ', b*n=' '*[style=[textalign=center cellwidth=3em]] / box='a';
run;

ods html close;
输出: