0

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

D. Studer
  • 1,711
  • 1
  • 16
  • 35

2 Answers2

3

Use FREQ statement

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;
data _null_
  • 8,534
  • 12
  • 14
1

Why not use normal datastep to duplicate row? Than do what every you wanted.

data want;
  set have;
  do _i = 1 to count;
    output;
  run;
  drop _i;
run;
proc print;run;
Lee
  • 1,427
  • 9
  • 17