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

Hello,

I created formats and labels for my variables, but when I create tables, the variable name (ex: newrace) is displaying in addition to the label I created. I want only the label to show (ex: Race) and I am not sure what I'm doing wrong?

[My formatted values appear the way I want them to and replace their values of 1 and 0 (ex: Yes No)]

 

Data library.dataset;
set dataset;
Label
sad="Sad for 2 or more weeks during the past 12 months"

newrace="Race"

;

run;

proc freq data=library.datasetorder=freq;
format newrace race. sad yesno.;
table newrace*sad;
run;

fastandcurious_0-1691760750864.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you must use proc freq, and custom reporting is better done in either Proc Tabulate or Report, you would have to modify the ODS templates that the procedure uses and would likely mean more than one as one-way frequency and two-way frequency tables differ.

 

An example:

proc tabulate data=library.dataset;
   class newrace /order=freq;
   class sad;
   format newrace race. sad yesno.;
   table newrace all='Total',
         (sad all='Total') * (n='Count' pctn='table %')
         ;
run;

Proc tabulate will display the label, if one is defined, by default and no variable name. You can modify the displayed label in use with the overide variable='some text' in a table statement as shown with the statistics. The ALL is to get a summary of the combined class variable.  Note that the comma is used to separate dimensions. In the example the first dimension is only the newrace variable. If you also, for example, had an Age variable on the same line you would have a single table with race values above the age values. The * is used to nest variables and/or statistics and ( ) create a display group treated together. If you used something like newrace*age you would get each age as a row within a race category.

 

 

View solution in original post

4 REPLIES 4
Reeza
Super User
Use TABULATE procedure instead, you have more control there.
ballardw
Super User

If you must use proc freq, and custom reporting is better done in either Proc Tabulate or Report, you would have to modify the ODS templates that the procedure uses and would likely mean more than one as one-way frequency and two-way frequency tables differ.

 

An example:

proc tabulate data=library.dataset;
   class newrace /order=freq;
   class sad;
   format newrace race. sad yesno.;
   table newrace all='Total',
         (sad all='Total') * (n='Count' pctn='table %')
         ;
run;

Proc tabulate will display the label, if one is defined, by default and no variable name. You can modify the displayed label in use with the overide variable='some text' in a table statement as shown with the statistics. The ALL is to get a summary of the combined class variable.  Note that the comma is used to separate dimensions. In the example the first dimension is only the newrace variable. If you also, for example, had an Age variable on the same line you would have a single table with race values above the age values. The * is used to nest variables and/or statistics and ( ) create a display group treated together. If you used something like newrace*age you would get each age as a row within a race category.

 

 

fastandcurious
Obsidian | Level 7
Thank you for this example and feedback, I'll try proc tabulate and report and share the results. I am not as familiar with them but it sounds like the best way to get labels in the output
fastandcurious
Obsidian | Level 7

Thank you, this code worked for displaying the labels the way I hoped to! 

fastandcurious_0-1691766329070.png

 

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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