BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

This code calculate frequency of two way table .

In each cell we get number of rows.

I want to ask what is the way to create same structure of table with percent from total in each row.

For example:In first row there will be:

3/158=1/9% ,25/158=15.82% ,94/158=59.49%,17/158=10.76%,8/158=5.06%,11/158=6.96% ,158/158=100%

I want to see the results in Percent format with % symbol

What is the way to do it please?

proc tabulate data=sashelp.cars missing;
Title 'Two Way freq table';
class Origin  Type;
var MSRP;
table Origin='' ALL,Type='Type Of car'*N=''*MSRP=''*F=Comma21. ALL/box='Origin of Car' misstext='0' ;
run;
4 REPLIES 4
ballardw
Super User

I don't have a clue what you are doing with MSRP.

 

If you really want to see a % sign you have two choices. One is to make and use a VAR variable that is numeric with the MEAN statistic that will make the correct values and a percent format. Typically that new variable would be 1/0 coded variable with 1 meaning the characteristic of interest.

 

Or if you want to use ROWPCTN you need to make format that will look like a percent such as:

proc format;
picture fakepercent
low-high = '009.99%'
;
run;

proc tabulate data=sashelp.cars missing;
Title 'Two Way freq table';
class Origin  Type;
var MSRP;
table Origin='' ALL,
     Type='Type Of car'*rowpctN=''*f=fakepercent. ALL
     /box='Origin of Car' misstext='0' ;
run;

If the only missing text will be with the percent then you would set misstext='0%' or similar. However if you may have more than one value missing your percents are going to look like your misstext setting. In which case perhaps a blank will be less jarring in appearance than a column/row with mixed percent signs and not.

 

Personally, I find % in a table to be messy.

Astounding
PROC Star

How about simplifying life:

 

proc freq data=sashelp.cars;
   table Origin * Type / nocol nopercent nofreq;
   label Origin = 'Origin of Car'  type='Type of Car';
run;
ballardw
Super User

@Astounding wrote:

How about simplifying life:

 

proc freq data=sashelp.cars;
   table Origin * Type / nocol nopercent nofreq;
   label Origin = 'Origin of Car'  type='Type of Car';
run;

OP explicitly states he wants the percent sign:

3/158=1/9% ,25/158=15.82% ,94/158=59.49%,17/158=10.76%,8/158=5.06%,11/158=6.96% ,158/158=100%

I want to see the results in Percent format with % symbol

Proc freq won't show the %.

 

Watts
SAS Employee

In recent releases of PROC FREQ, you can use the FORMATP= option in the TABLES statement to format the percentages in crosstabulation tables. 

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 3397 views
  • 0 likes
  • 4 in conversation