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
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.
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;
Thanks for the reply ballardw. 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
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.
Hi ballardw ,
Here is my dataset......
Sno | Honda | VW | Maruti | Gender |
1 | 7 | 4 | 4 | 1 |
2 | 3 | 3 | 3 | 2 |
3 | 4 | 3 | 7 | 1 |
4 | 5 | 7 | 5 | 1 |
5 | 1 | 1 | 1 | 2 |
6 | 1 | 1 | 1 | 1 |
7 | 3 | 3 | 2 | 1 |
8 | 4 | 7 | 4 | 2 |
9 | 5 | 5 | 5 | 1 |
10 | 3 | 3 | 7 | 2 |
11 | 2 | 2 | 2 | 2 |
12 | 3 | 3 | 5 | 1 |
13 | 4 | 4 | 4 | 2 |
14 | 5 | 5 | 5 | 2 |
15 | 4 | 1 | 4 | 1 |
16 | 1 | 1 | 1 | 2 |
17 | 3 | 3 | 6 | 2 |
18 | 4 | 1 | 4 | 2 |
19 | 5 | 5 | 5 | 1 |
20 | 4 | 4 | 4 | 2 |
21 | 1 | 1 | 1 | 2 |
22 | 7 | 3 | 6 | 2 |
23 | 4 | 6 | 4 | 2 |
24 | 2 | 2 | 2 | 1 |
25 | 3 | 3 | 3 | 2 |
26 | 1 | 1 | 1 | 2 |
27 | 3 | 3 | 3 | 1 |
28 | 4 | 4 | 4 | 2 |
29 | 5 | 4 | 5 | 1 |
30 | 7 | 6 | 7 | 2 |
And the output that i what is in my first discussion page.....
Thanks,
Sandeep.K
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.