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

Is there a way to graph means and proportions derived from PROC MEANS and PROC FREQ across 3 time points (var = timepoint)?

PROC MEANS DATA=kb.data_01 maxdec=1;
	VAR 
	promis_pain_intensity 
	promis_pain_interference 
	;
	CLASS timepoint;
	TITLE "Descriptive Statistics for Continuous Measures";
RUN;
PROC FREQ DATA=kb.data_01 ORDER=FREQ; 
	/*   by timepoint ; */
TABLE aes_yn dose adherence satisfaction / PLOTS=(freqplot); TITLE "Descriptive Statistics for Categorical Measures"; RUN;

Also, 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
To debug something like this, add your options/statements one by one until you find the one that's breaking it. Then look up that option in the documentatation and see which is causing the issue.

My guess, your X axis values 0 to 2 but you have formatted values may be causing the issue. Your original code didn't have a format so if that was actually in the code it may be part of the issue.

View solution in original post

15 REPLIES 15
Reeza
Super User

First you'd use PROC MEANS and FREQ to save the output to a data set. Depending on exactly what you want you may be able to plot it directly from the raw data or need to pre-summarize the data. 

Here's some instructions and explanations on how to capture output that is shown.
https://blogs.sas.com/content/sastraining/2017/03/31/capturing-output-from-any-procedure-with-an-ods...

 

I've included examples below for you.

 

If your variables are binary then you can also use the fact that the average of a 0/1 variable is the percentage or proportion of the variable. 

 

PROC MEANS DATA=kb.data_01 maxdec=1;
	VAR 
	promis_pain_intensity 
	promis_pain_interference 
	;
	CLASS timepoint;
	TITLE "Descriptive Statistics for Continuous Measures";
ods output summary = want_means;
RUN;
PROC FREQ DATA=kb.data_01 ORDER=FREQ; 
	/*   by timepoint ; */    TABLE  
	aes_yn
	dose 
	adherence
	satisfaction
	 / PLOTS=(freqplot);
	TITLE "Descriptive Statistics for Categorical Measures";
ods output onewayfreq=want_freq;
RUN; 

Graphing it may be harder, depends on exactly what you're looking for. 

 

Here's some examples of common graph types. There are fully worked examples here so you can follow the code/output together.

https://robslink.com/SAS/ods2/aaaindex.htm

 

If you have more specific questions please feel free to ask!

 


@_maldini_ wrote:

Is there a way to graph means and proportions derived from PROC MEANS and PROC FREQ across 3 time points (var = timepoint)?

PROC MEANS DATA=kb.data_01 maxdec=1;
	VAR 
	promis_pain_intensity 
	promis_pain_interference 
	;
	CLASS timepoint;
	TITLE "Descriptive Statistics for Continuous Measures";
RUN;
PROC FREQ DATA=kb.data_01 ORDER=FREQ; 
	/*   by timepoint ; */
TABLE aes_yn dose adherence satisfaction / PLOTS=(freqplot); TITLE "Descriptive Statistics for Categorical Measures"; RUN;

Also, 

 


 

_maldini_
Barite | Level 11

This is great. Thank you!

A few other questions. The syntax below seems to work, but I can't seem to figure out the proc sgplot syntax.

 

Proc means data=kb.data_01 maxdec=1;
	var 
	age
	promis_pain_intensity 
	promis_pain_interference 
	;
	class timepoint;
	title "Descriptive Statistics for Continuous Measures";
	ods output summary = want_means;
run;

proc print data=want_means;
var promis_pain_interference_Mean promis_pain_intensity_Mean;
by timepoint;
run;

Screen Shot 2021-10-27 at 9.42.04 AM.png

 

 

 

 

 

 

 

 

 

 

 

I've done my best to adapt the code from the desired robslink.com page, but the means aren't plotted on the graph (see below).
Screen Shot 2021-10-27 at 9.45.32 AM.png

ods graphics / attrpriority=none;
proc sgplot data=want_means aspect=1 noautolegend;
styleattrs datasymbols=(diamondfilled squarefilled) 
 datacontrastcolors=(navy magenta) datalinepatterns=(solid);
series x=timepoint y=promis_pain_interference_Mean / lineattrs=(thickness=3px)
 markers markerattrs=(size=12pt);
yaxis
 values=(4 to 20 by 1) label='PROMIS Pain Interference Score (Mean)'
 labelattrs=(size=16pt weight=bold color=gray33)
 valueattrs=(size=16pt weight=bold color=gray33)
 offsetmin=0 offsetmax=0 grid minor minorcount=3;
xaxis
 values=(0 to 2 by 1) label='Timepoint'
 labelattrs=(size=16pt weight=bold color=gray33)
 valueattrs=(size=16pt weight=bold color=gray33)
 offsetmin=0 offsetmax=0 grid minor minorcount=3;
run;
quit;
ODS HTML CLOSE;
ODS LISTING;

Any clues in my syntax? Also, do you know how I would add SD bars?

 

Thanks again!

 

_maldini_
Barite | Level 11

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
NOTE: ODS statements in the SAS Studio environment may disable some output features.
69
70 ods graphics / attrpriority=none;
71 proc sgplot data=want_means aspect=1 noautolegend;
72 styleattrs datasymbols=(diamondfilled squarefilled)
73 datacontrastcolors=(navy magenta) datalinepatterns=(solid);
74 series x=timepoint y=promis_pain_interference_Mean / lineattrs=(thickness=3px)
75 markers markerattrs=(size=12pt);
76 yaxis
77 values=(4 to 20 by 1) label='PROMIS Pain Interference Score (Mean)'
78 labelattrs=(size=16pt weight=bold color=gray33)
79 valueattrs=(size=16pt weight=bold color=gray33)
80 offsetmin=0 offsetmax=0 grid minor minorcount=3;
81 xaxis
82 values=(0 to 2 by 1) label='Timepoint'
83 labelattrs=(size=16pt weight=bold color=gray33)
84 valueattrs=(size=16pt weight=bold color=gray33)
85 offsetmin=0 offsetmax=0 grid minor minorcount=3;
86 run;

NOTE: PROCEDURE SGPLOT used (Total process time):
real time 0.11 seconds
user cpu time 0.05 seconds
system cpu time 0.01 seconds
memory 8307.78k
OS Memory 34604.00k
Timestamp 10/27/2021 05:33:32 PM
Step Count 207 Switch Count 1
Page Faults 0
Page Reclaims 1337
Page Swaps 0
Voluntary Context Switches 153
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 512

NOTE: Some of the tick values have been thinned.
NOTE: There were 3 observations read from the data set WORK.WANT_MEANS.

87 quit;
88 ODS HTML CLOSE;
89 ODS LISTING;
90
91 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
101
_maldini_
Barite | Level 11
Also, how would I incorporate a group variable in the proc means that would also be output to the new dataset? For example, if I wanted to plot the change in means of males and females?
_maldini_
Barite | Level 11
SAS doesn't like the "onewayfreq" statement?

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

WARNING: Output 'onewayfreq' was not created. Make sure that the output object name, label, or path is spelled correctly. Also,
verify that the appropriate procedure options are used to produce the requested output object. For example, verify that
the NOPRINT option is not used.
Reeza
Super User
Ah...it's onewayfreqs missed the S there.

Your graphs shouldn't have been affected as that's the want_means data set though.
You didn't show the log for the graph portion though.
_maldini_
Barite | Level 11
I just posted it above.
_maldini_
Barite | Level 11
Does the log help explain why the means aren't showing up on the graph?
_maldini_
Barite | Level 11

@Reeza 

It looks like the problem lies in the commented-out syntax. When I run it w/o specifying details about the x and y axis, I get this graph:

Screen Shot 2021-10-28 at 11.46.09 AM.png


 

proc sgplot data=want_means;
	series x=timepoint y=promis_pain_intensity_Mean / lineattrs=(thickness=3px) 
		markers markerattrs=(size=10pt);

	/* yaxis */
	/*  values=(3 to 15 by 1) label='PROMIS Pain Intensity Score (Mean)' */
	/*  labelattrs=(size=14pt weight=bold color=gray33) */
	/*  valueattrs=(size=14pt weight=bold color=gray33) */
	/*  offsetmin=0 offsetmax=0 grid minor minorcount=1; */
	/*   */
	
	/* xaxis */
	/*  values=(0 to 2 by 1) label='Timepoint' */
	/*  labelattrs=(size=14pt weight=bold color=gray33) */
	/*  valueattrs=(size=14pt weight=bold color=gray33) */
	/*  offsetmin=0 offsetmax=0 grid minor minorcount=1; */
	
	format Timepoint $timepoint_.;
run;

Maybe you could point me in the direction of some alternative syntax for customizing the axes?

 

Thanks!

 

Reeza
Super User
To debug something like this, add your options/statements one by one until you find the one that's breaking it. Then look up that option in the documentatation and see which is causing the issue.

My guess, your X axis values 0 to 2 but you have formatted values may be causing the issue. Your original code didn't have a format so if that was actually in the code it may be part of the issue.
_maldini_
Barite | Level 11

You were correct. It was a format issue. The problem is resolve and I will accept this as the solution. Thanks!

Is there an option for adding the value of the data point to the graph? I can't seem to find one in the documentation.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 15 replies
  • 1988 views
  • 5 likes
  • 2 in conversation