Hello-
I recently inherited a program that uses Proc tabulate. I'm not familiar with this proc and I was asked to modify the way the table looks. I have to move the count and % values so they are colums next to each other .
The table needs to look something like this:
| Yes | No | Total | ||||
| Unit | Count | % | Count | % | Count | % |
| Unit1 | 2 | 22.2% | 5 | 50% | 7 | 36.8% |
| Unit2 | 3 | 33.3% | 5 | 50% | 8 | 42.1% |
| Total | 9 | 10 | 19 | |||
Currently, the %'s fall under the Unit counts. I've tried moving things around but can't seem to get the right result.
Here is what I have right now:
Does anyone have any thoughts?
proc tabulate data=have
style=font_size=8pt};
class quest unit answer /
style={ font_size=9pt};
classlev question unit answer /
style={font_size=9pt};
tables quest=' ',
unit=' '*(n pagepctn*f=pctfmt.) all*(npagepctn*f=pctfmt.),
answer =' 'all
/ row=float
box={label='Number^{newline 1}Overall^_%' style={ =9pt}};
keylabelall='Total'
n=' '
pagepctn=' ';
keyword all n pagepctn/
style={ font_size=8pt};
Any feedback would be very helpful!
Thanks.
It would help others on the forum if you also post a copy of your have dataset.
ok, the dataset looks something like this:
data have;
infile datalines dlm=',' dsd;
input unit $ question answer;
return;
datalines;
"Unit1",1,1
"Unit1 ",1,0
"Unit1 ",1,1
"Unit1 ",1,0
"Unit1 ",1,1
" Unit2",1,1
" Unit2",1,1
" Unit2",1,0
" Unit2",1,1
" Unit2",1,0;
run;
I also apply formats to "Question" and "Answer". Thanks.
Is it what you are looking for ?
proc format; value x 1 = 'Yes' 0 = 'No' ; picture p low-high='0099%'; run; data have; infile datalines dlm=',' dsd; input unit $ question answer; format answer x.; datalines; "Unit1",1,1 "Unit1 ",1,0 "Unit1 ",1,1 "Unit1 ",1,0 "Unit1 ",1,1 " Unit2",1,1 " Unit2",1,1 " Unit2",1,0 " Unit2",1,1 " Unit2",1,0 ; run; proc tabulate data=have; class unit answer; table unit all,n='Count'*f=best8.*(answer='' all='Total') pctn='%'*f=p.*(answer='' all='Total') ; run;
Ksharp
Thank you. I will try this out and let you know.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.