BookmarkSubscribeRSS Feed
JennyB
Calcite | Level 5

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
UnitCount   %Count  %Count   %
Unit1   222.2%550%736.8%
Unit2   333.3%550%842.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.

4 REPLIES 4
art297
Opal | Level 21

It would help others on the forum if you also post a copy of your have dataset.

JennyB
Calcite | Level 5

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.

Ksharp
Super User

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

JennyB
Calcite | Level 5

Thank you. I will try this out and let you know.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1277 views
  • 0 likes
  • 3 in conversation