BookmarkSubscribeRSS Feed
DavidKaib
Fluorite | Level 6

I am using this code:

proc freq;
tables VAR1 * VAR2 /nocum nopercent norow NOFREQ;
run;

 

To produce this output:

VAR1VAR2  
   Total
 OneTwo 
A47.7967.86 
B31.8628.57 
C15.930 
D4.423.57 
Total11328141

 

Which is exactly what I need, except I would like to remove the decimal points. How can I do that?

3 REPLIES 3
Tom
Super User Tom
Super User

Is PROC FREQ even what you want to use for this?

 

I am not sure I understand what you are trying to do.  Especially since you did not provide any actual data.   Based on the column percents and totals you provided it looks your data looks like this:

data have ;
  input var1 :$1. @;
  do var2='One','Two';
    input count @;
    output;
  end;
cards;    
A 54 19
B 36  8
C 18  0
D 5   1
;

Why do you want to print the column percentages without the decimal places?

Why do you want to print the column percentages and the raw totals in the same column of your report?

Ksharp
Super User

You need to customize a template for this purpose. 

Here take sashelp.heart as an example:

 

ods noproctitle;
ods path (prepend) work.templat(update);
proc template;
edit Base.Freq.CrossTabFreqs;
edit Frequency;
format=COMMA12.;
end;
edit Percent;
format=8.0;
end;
edit RowPercent;
format=8.0;
end;
edit ColPercent;
format=8.0;
end;
end;
run;
/**/
/*ods html file="userfmt.html" style=daisy;*/
/*title "Applying Custom Formats to Cellvalues";*/
/*proc freq;*/
/*tables citygovt*robgrp / missprint;*/
/*run;*/
/*ods html close;*/


proc freq data=sashelp.heart;
tables bp_status * sex /nocum nopercent norow NOFREQ ;
run;

Ksharp_0-1788435202710.png

 

FreelanceReinh
Jade | Level 19

Hello @DavidKaib,

 

Do you want to get 48 instead of 47.79, ..., 4 instead of 4.42, ... as the column percentages? If so, you could modify the corresponding ODS template, but make sure not to corrupt the original template.

 

For example, if I submit

ods path show;

in a SAS session using the RSASUSER system option, I get

1. WORK.TEMPLAT(UPDATE)
2. SASUSER.TEMPLAT(READ)
3. SASHELP.TMPLMST(READ)

which means that the relevant original template Base.Freq.CrossTabFreqs in SASHELP.TMPLMST is read-only and modifications would be written to the temporary WORK.TEMPLAT template store. So I can safely apply the EDIT statement of the TEMPLATE procedure to ColPercent to change the format of the column percentages from the default 6.2 to the 3. format:

proc template;
edit Base.Freq.CrossTabFreqs;

  edit ColPercent;
    format=3.;
  end;

end;
run;

Subsequent PROC FREQ outputs in the same session use the modified format until I delete the modified template.

proc template;
delete Base.Freq.CrossTabFreqs;
run;

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 3 replies
  • 269 views
  • 2 likes
  • 4 in conversation