BookmarkSubscribeRSS Feed
Sandeepkumar
Calcite | Level 5

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

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ballardw
Super User

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;

Sandeepkumar
Calcite | Level 5

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

ballardw
Super User

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.

Sandeepkumar
Calcite | Level 5

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

ballardw
Super User

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.

Reeza
Super User

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 744 views
  • 0 likes
  • 4 in conversation