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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 678 views
  • 4 likes
  • 3 in conversation