I have the following data
DATA HAVE;
input year dz $8. area;
cards;
2000 stroke 08
2000 stroke 06
2000 stroke 06
;
run;
After using the proc tabulate
proc tabulate data=have;
class area dz;
table area, dz*(n colpctn);
run;
I get the below output
I want to replace any values below 5 in "N" column and 0 in "ColPctN" column with "<5" and "0", respectively.
I have the below proc format code
proc format;
picture count (round)
0-4 = ' <5' (NOEDIT);
picture pcnt (round)
0 = ' - '
other = '009.9%';
But I am not understanding how to use it in the data step to get the desired results. Please guide.
Thanks!
Refer to the documentation for the procedures you are trying to use to see what options they support.
For PROC FREQ just send the counts to a dataset and then print the dataset.
proc freq data=have;
tables area * dz / noprint out=counts;
run;
proc print data=counts;
format count fcount. percent pcnt. ;
run;.
Next code demonstrates the usage of format in proc tabulate:
DATA HAVE;
input year dz $8. area;
cards;
2000 stroke 08
2000 stroke 06
2000 stroke 06
;
run;
proc format;
picture count (round)
0-4 = ' <5' (NOEDIT);
picture pcnt (round)
0 = ' - '
other = '009.9%';
run;
proc tabulate data=have;
class area dz;
table area, dz*(n*f=count. colpctn*f=pcnt.);
run;
With proc freq try - though I am sceptic about variable names to use:
proc freq data=have;
format frequency fcount. percent pcnt.;
tables area * dz / list nocum ;
run;.
Refer to the documentation for the procedures you are trying to use to see what options they support.
For PROC FREQ just send the counts to a dataset and then print the dataset.
proc freq data=have;
tables area * dz / noprint out=counts;
run;
proc print data=counts;
format count fcount. percent pcnt. ;
run;.
Yes, it is possible. Change proc tabulate line to:
n='Frequency'*f=count. pctn='Percent'*f=fpcnt.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.