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

Hi!

I have the following data

DATA HAVE;
input year dz area;
cards;
2000 1 08
2000 1 06
2000 1 06
;
run;

 

proc freq data=have;
table area*dz / norow nocol;
run;

 

I get the following output

Priyamvada07_0-1616740380414.png

I would like to format it to put frequency in one column and percent in another column (and I don't want the total column) rather than the default SAS output. Is there a way to do it?

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

I don't know how to get the expected output with proc freq. Proc tabulate could be used:

proc tabulate data=have;
   class area;
   var dz;

   table area, dz*(n colpctn);
run;

View solution in original post

7 REPLIES 7
andreas_lds
Jade | Level 19

I don't know how to get the expected output with proc freq. Proc tabulate could be used:

proc tabulate data=have;
   class area;
   var dz;

   table area, dz*(n colpctn);
run;
Priyamvada07
Obsidian | Level 7

Thank you, proc tabulate does the work but only for numeric variables. Can I use proc tabulate to get similar output if one of the variables is a character variable?

DATA HAVE;
input year dz $8. area;
cards;
2000 stroke 08
2000 stroke 06
2000 stroke 06
;
run;

 

when I use the code provided, it gives me: ERROR: Variable dz in list does not match type prescribed for this list.

 

Thank you!

andreas_lds
Jade | Level 19

Just move dz from the var statement into the class statement and remove the empty var statement.

Priyamvada07
Obsidian | Level 7
Hi! I just realized when using proc tabulate I am missing the last row that is the 'total' as seen in my output image in the original question. Is there a way to retain the 'total' column?
andreas_lds
Jade | Level 19

@Priyamvada07 wrote:
Hi! I just realized when using proc tabulate I am missing the last row that is the 'total' as seen in my output image in the original question. Is there a way to retain the 'total' column?

Yes, of course using the "all" keyword in the tables-statement. Can't test it now, but the following code should work.

proc tabulate data=have;
   class area;
   var dz;

   table area all, dz*(n colpctn);
run;
Watts
SAS Employee

You can use the LIST option in PROC FREQ. 

proc freq data=have;
tables area * dz / list nocum;
run;

The NOCUM option suppresses the cumulative frequencies and percents. 

 

Priyamvada07
Obsidian | Level 7
Hi! I just realized when using this code I am missing the last row that is the 'total' as seen in my output image in the original question. Is there a way to retain the 'total' column?

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