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 proc freq
proc freq data=have;
table area*dz/ list nocum ;
run;
I get the below output
In this output
1. I want to delete the 'dz', what can I do to delete this column?
2. I want a row in the end that gives 'total', what can I do to get a 'total' row?
Thank you!
What would go on that "total" row?
Your Have data step is likely incorrect and you want either (if dz is supposed to be only "stroke" and area is numeric
DATA HAVE; input year dz :$8. area; cards; 2000 stroke 08 2000 stroke 06 2000 stroke 06 ; run;
OR if area is supposed to be character.
DATA HAVE; input year dz :$8. area $; cards; 2000 stroke 08 2000 stroke 06 2000 stroke 06 ; run;
I suspect you are not providing enough information as with this small sample you get the same counts and percentages with:
proc freq data=have; tables area; run;
Perhaps you are looking for a different reporting procedure. Here is a "total" row done with Proc Tabulate:
proc tabulate data=have; class area; tables area=' ' all='Total', n='Frequency' pctn='Percent' /box=area ; run;
Tabulate has a different set of options as it does different statistics and has the ability to nest variables in both row, column and Page(separate table) dimensions. The Area=' ' suppresses the default label of the Area variable, box places it into what would normally be an empty box in the upper left. "All" requests a total within a dimension, the ='Total' provides a label. N requests a count and Pctn asks for the basic percentage and again the ='text' provides a label other than the default N or PCTN.
What would go on that "total" row?
Your Have data step is likely incorrect and you want either (if dz is supposed to be only "stroke" and area is numeric
DATA HAVE; input year dz :$8. area; cards; 2000 stroke 08 2000 stroke 06 2000 stroke 06 ; run;
OR if area is supposed to be character.
DATA HAVE; input year dz :$8. area $; cards; 2000 stroke 08 2000 stroke 06 2000 stroke 06 ; run;
I suspect you are not providing enough information as with this small sample you get the same counts and percentages with:
proc freq data=have; tables area; run;
Perhaps you are looking for a different reporting procedure. Here is a "total" row done with Proc Tabulate:
proc tabulate data=have; class area; tables area=' ' all='Total', n='Frequency' pctn='Percent' /box=area ; run;
Tabulate has a different set of options as it does different statistics and has the ability to nest variables in both row, column and Page(separate table) dimensions. The Area=' ' suppresses the default label of the Area variable, box places it into what would normally be an empty box in the upper left. "All" requests a total within a dimension, the ='Total' provides a label. N requests a count and Pctn asks for the basic percentage and again the ='text' provides a label other than the default N or PCTN.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.