BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Priyamvada07
Obsidian | Level 7

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

Priyamvada07_0-1617084939992.png

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

View solution in original post

8 REPLIES 8
Shmuel
Garnet | Level 18

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;
Priyamvada07
Obsidian | Level 7
Thank you Shmuel! This works, however I was wondering how to use it in proc freq, I tried using it this way
proc freq data=have;
tables area * dz / list nocum (frequency=fcount. percent=pcnt.);
run;.
But it doesn't work!
Shmuel
Garnet | Level 18

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;.
Priyamvada07
Obsidian | Level 7
When I do that it doesn't work!
I get the following in the log

36 proc freq data=have;
37 format frequency count. percent pcnt.;
WARNING: Variable FREQUENCY not found in data set WORK.HAVE.
WARNING: Variable PERCENT not found in data set WORK.HAVE.
38 tables area * dz / list nocum ;
39 run;

Thanks.
Tom
Super User Tom
Super User

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;.
Priyamvada07
Obsidian | Level 7
I am using the following updated code for proc tabulate. Is there a way to format 'n' and 'pctn' and at the same time rename them to 'Frequency' and 'Percent', respectively?

proc format;
picture count (round)
0-4 = ' <5' (NOEDIT);
picture pcnt (round)
0 = ' - '
other = '009.9%';

proc tabulate data=have;
class area;
tables area=' ' all='Total',
n='Frequency' pctn='Percent'
/box=area;
run;

I have tried using the following but its not working
proc tabulate data=have;
class area;
tables area=' ' all='Total',

({n*f=count.}='Frequency') ({pctn*f=pcnt.}='Percent')
/box=area;
run;
Shmuel
Garnet | Level 18

Yes, it is possible. Change proc tabulate line to:

n='Frequency'*f=count.   pctn='Percent'*f=fpcnt. 
Priyamvada07
Obsidian | Level 7
Worked perfectly! Thank you.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register 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
  • 8 replies
  • 1223 views
  • 9 likes
  • 3 in conversation