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

Why are variable labels being applied inconsistently when using PROC FREQ PLOTS=FREQPLOT (See images). All labels are coded and applied the exact same way in a DATA step. All variables are included in one PROC FREQ, but some labels appear at the bottom of the freq plots and others don't. Any ideas?

 

Screen Shot 2021-11-04 at 9.50.49 AM.pngScreen Shot 2021-11-04 at 9.51.54 AM.png

 

Also, unrelated question, is there a way to have each level of a categorical variable appear as a row in a proc freq table regardless of whether its values are missing? In other words, if the variable has 4 levels (i.e., poor, good, very good, excellent) and there are only responses for 2 levels (i.e., very good, excellent), how can you include rows for "poor" and "neutral" w/ counts of "0", instead of simply not including those rows in the table? I'd like to be able to visualize all the possible responses, even if there are none for a given response.

Screen Shot 2021-11-04 at 9.58.05 AM.png

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

You can either shorten the label or widen the plot.

To widen the plot, use the ODS GRAPHICS statement:

ODS GRAPHICS/ width=1000px height=500px;    /* adjust the values as needed */

 

To change the label, use the LABEL statement inside the PROC FREQ code:

proc freq;
label source="Describe the location of your pain";
...
run;

View solution in original post

5 REPLIES 5
Reeza
Super User
Show your code and log. I suspect when the label is too long to fit on the graph it defaults to the variable name but it usually puts a note in the log when that happens.
_maldini_
Barite | Level 11
Proc freq data=kb.data_01 ORDER=FREQ ;
	/* 	where timepoint = "fu_1_arm_2"; */
	/* 	 by timepoint ; */
	table
		source
		location_pn
		oral_meds_yn
		top_meds_yn
		aes_yn
		aes_sev
		aes_hc
		aes_acn
		aes_out
		dose freq
		adherence
		satisfaction
		saf_effec / plots=freqplot (scale=percent);

	/* 	FORMAT advise yes_no_fmt.; */

	TITLE "Descriptive Statistics for Categorical Measures";
	ods output onewayfreqs=want_freq;
RUN;


1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
NOTE: ODS statements in the SAS Studio environment may disable some output features.
69
70 /*
70 ! -------------------------------------------------------------------------------------------------------------------------
70 ! -------- */
71 Proc freq data=kb.data_01 ORDER=FREQ ;
72 /* where timepoint = "fu_1_arm_2"; */
73 /* by timepoint ; */
74 table
75 source
76 location_pn
77 oral_meds_yn
78 top_meds_yn
79 aes_yn
80 aes_sev
81 aes_hc
82 aes_acn
83 aes_out
84 dose freq
85 adherence
86 satisfaction
87 saf_effec / plots=freqplot (scale=percent);
88
89 /* FORMAT advise yes_no_fmt.; */
90
91 TITLE "Descriptive Statistics for Categorical Measures";
92 ods output onewayfreqs=want_freq;
93 RUN;

NOTE: No plots are displayed for the table of aes_sev because all data are missing.
NOTE: No plots are displayed for the table of aes_hc because all data are missing.
NOTE: No plots are displayed for the table of aes_acn because all data are missing.
NOTE: No plots are displayed for the table of aes_out because all data are missing.
NOTE: The data set WORK.WANT_FREQ has 34 observations and 33 variables.
NOTE: There were 40 observations read from the data set KB.DATA_01.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.92 seconds
user cpu time 0.59 seconds
system cpu time 0.05 seconds
memory 11379.96k
OS Memory 37428.00k
Timestamp 11/04/2021 05:25:07 PM
Step Count 180 Switch Count 60
Page Faults 0
Page Reclaims 4726
Page Swaps 0
Voluntary Context Switches 1662
Involuntary Context Switches 18
Block Input Operations 0
Block Output Operations 6072


94
95 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
105

ballardw
Super User

@_maldini_ wrote:

 

Also, unrelated question, is there a way to have each level of a categorical variable appear as a row in a proc freq table regardless of whether its values are missing? In other words, if the variable has 4 levels (i.e., poor, good, very good, excellent) and there are only responses for 2 levels (i.e., very good, excellent), how can you include rows for "poor" and "neutral" w/ counts of "0", instead of simply not including those rows in the table? I'd like to be able to visualize all the possible responses, even if there are none for a given response.

Screen Shot 2021-11-04 at 9.58.05 AM.png

Thanks!


Not with Proc Freq.

Procs Report, Tabulate and Means/Summary support an option called PRELOADFMT which will display all the values that appear in a finite-list format applied to a variable when proper syntax is used and you have defined a format with all the values you want to appear.

 

Consider, if a data set does not have a specific value for any record where is SAS supposed to know that value should be reported on? Somewhere you will have to provide that information.

 

A brief example:

data example;
   input scale $;
datalines;
poor
good
;

Proc format library=work;
value $scale
'poor'     ='Poor'     
'good'     ='Good'     
'very good'='Very good'
'excellent'='Excellent'
;
run;

proc tabulate data=example;
   class scale/preloadfmt;
   format scale $scale.;
   table scale,
         n colpctn
         /printmiss ;
run;

Key elements: 1) a format  2) a procedure that supports Preloadfmt 3) proper syntax, in this case the option for the variable to use the preloaded format, associate the format you want with the variable (note: you could have a format that combines levels into a single displayed text) and any other syntax elements need, in this case the Printmiss option to print the missing levels of the format.

Rick_SAS
SAS Super FREQ

You can either shorten the label or widen the plot.

To widen the plot, use the ODS GRAPHICS statement:

ODS GRAPHICS/ width=1000px height=500px;    /* adjust the values as needed */

 

To change the label, use the LABEL statement inside the PROC FREQ code:

proc freq;
label source="Describe the location of your pain";
...
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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