简体   繁体   English

SAS中的加权交叉表

[英]weighted crosstable in SAS

Let's assume I have the following table: 假设我有下表:

id | var1 | var2 | count
1  | a    | b    | 3
2  | b    | a    | 4 
3  | c    | e    | 1

Now I would like to calculate a crosstable: 现在,我想计算一个交叉表:

PROC TABULATE;
   CLASS var1 var2;
   TABLE var1, var2;
RUN;

However, my problem is that a count -variable of lets say 4 signifies that the particular case should actually appear 4 times in the table. 但是,我的问题是,让4的count变量表示该特定情况实际上应该在表中出现4次。 So the table above should be: 因此,上表应为:

id | var1 | var2 | count
1  | a    | b    | 3
1  | a    | b    | 3
1  | a    | b    | 3
2  | b    | a    | 4 
2  | b    | a    | 4 
2  | b    | a    | 4 
2  | b    | a    | 4 
3  | c    | e    | 1

Is there a possibility to weight the number of cases directly within PROC TABULAR or how can I add additional cases according to the value of count ? 是否可以直接在PROC TABULAR案例数,或者如何根据count的值添加其他案例?

Use FREQ statement 使用FREQ语句

data test;
   infile cards dsd dlm='|' firstobs=2;
   input id (var1-var2)(:$1.) count;
   list;
   cards;
id | var1 | var2 | count
1  | a    | b    | 3
2  | b    | a    | 4 
3  | c    | e    | 1
;;;;
proc print;
   run;
PROC TABULATE;
   FREQ count;
   CLASS var1 var2;
   TABLE var1, var2;
   RUN;

Why not use normal datastep to duplicate row? 为什么不使用普通的datastep复制行? Than do what every you wanted. 比做任何您想做的事。

data want;
  set have;
  do _i = 1 to count;
    output;
  run;
  drop _i;
run;
proc print;run;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM