I am using this code:
proc freq;
tables VAR1 * VAR2 /nocum nopercent norow NOFREQ;
run;
To produce this output:
| VAR1 | VAR2 | ||
| Total | |||
| One | Two | ||
| A | 47.79 | 67.86 | |
| B | 31.86 | 28.57 | |
| C | 15.93 | 0 | |
| D | 4.42 | 3.57 | |
| Total | 113 | 28 | 141 |
Which is exactly what I need, except I would like to remove the decimal points. How can I do that?
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?
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;
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;
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
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.
Ready to level-up your skills? Choose your own adventure.