Using Proc tabulate or Proc report need the code for the following table format

Reply
Occasional Contributor
Posts: 16

Using Proc tabulate or Proc report need the code for the following table format

Hi,

In my dataset , there are 3 columns Q1, Q2, Q3 which contains 3 brands like Honda, VW, Maruti. For each column there is a rating scale question rated from 1 to 7.

Now i am looking for the code as per the following output using Proc tabulate or Proc report:

                                        Honda     VW     Maruti    

Base:All Respondents         30          30          30

7                                         5          6             9   

6                                       10           4            1  

5                                        5            2            5    

4                                        1            3            5  

3                                        3            5            2

2                                        2            5            3

1                                        5            5            5

Top2 Box [7/6]                    15          10          10

Middle 3 Box [3/4/5]             9           10          12

Botttom 2 Box [1/2]             7            10          8

Mean                                  4.5          4.3          4.2

Please kindly help me out with the above table format code.

Thanks in Advance.

Sandeep.K

Super User
Super User
Posts: 7,413

Re: Using Proc tabulate or Proc report need the code for the following table format

Please check out proc means - group by score for Honda, VW etc. then merge them back again.  The 7/6 3/4/5 1/2 you can either do manually via adding a variable group and then summing based on the group, or maybe even in the means procedure itself.

Super User
Posts: 10,538

Re: Using Proc tabulate or Proc report need the code for the following table format

You don't provide any example data or variable names and I'm too lazy to generate some to test but you should be able to do this in tabulate using a multilabel format.

Possibly

proc format;

value scalemulti (multilabel)

1 = '1'

2 = '2'

3 = '3'

4 = '4'

5 = '5'

6 = '6'

7 = '7'

1,2 = 'Bottom 2 box'

3,4,5 = 'Middle 3 box'

6,7 ='Top 2 box'

;

run;

proc tabulate data=have;

     class scale / order=descending mlf;

     format scale scalemulti.;

     class make;

     table scale , make * n;

run;

Occasional Contributor
Posts: 16

Re: Using Proc tabulate or Proc report need the code for the following table format

Thanks for the reply  . In your code, the variable "make" is used here as Column dimension.But I am looking for the 3 columns as side by side .

Can u please  try out with some other code.

Thanks,

Sandeep.K

Super User
Posts: 10,538

Re: Using Proc tabulate or Proc report need the code for the following table format

You get better results if you actually provide example data, variables contents and such. The documentation for proc tabulate will tell if you want multiple variables to appear in a dimension they must appear in either a Class or Var statement and then place them in the dimension.

If  my fake variable Make has three values it will generate 3 columns, one for each value.

What are the names of your "make" variables? How are they coded? Are they text or numeric? Do they have missing values - A VERY important piece of information when attempting to use proc tabulate.

Occasional Contributor
Posts: 16

Re: Using Proc tabulate or Proc report need the code for the following table format

Hi ballardw ,

Here is my dataset......

SnoHondaVWMarutiGender
17441
23332
34371
45751
51112
61111
73321
84742
95551
103372
112222
123351
134442
145552
154141
161112
173362
184142
195551
204442
211112
227362
234642
242221
253332
261112
273331
284442
295451
307672

And the output that i what is in my first discussion  page.....

Thanks,

Sandeep.K

Super User
Posts: 10,538

Re: Using Proc tabulate or Proc report need the code for the following table format

To have values appear as row or column headings in Proc tabulate you need a class variable. To provide the analysis with your data you will need to transform the data somewhat. Assuming the value under each of your makes is the value fo the scale you referenced something like this:

Data want (keep = sno gender scale make);

     set have;

     array m Honda VW Maruti;

     length make $ 8 ;

     do _i_=1 to dim(m);

          Scale=m[_i_];

          make= vname(m[_i_]);

          output;

     end;

     run;

And use the format and tabulate I previously posted above using the Want dataset.

Super User
Posts: 17,912

Re: Using Proc tabulate or Proc report need the code for the following table format

The documentation for proc tabulate has a good example of this. The ideal solution depends on your original data structure which you haven't provided.

Base SAS(R) 9.3 Procedures Guide, Second Edition

Ask a Question
Discussion stats
  • 7 replies
  • 345 views
  • 0 likes
  • 4 in conversation