BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Melk
Lapis Lazuli | Level 10

I have a vertical bar plot of means by visit number paneled by group.

 

Since I only have a few patients in my sample, I would like to overlay this plot with individual line plots. Is there an easy way to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

If I understand you correctly, then do something like this

 

data have;
input ID$ Visit Group Y;
datalines;
1 1 0 20
2 1 0 24
3 1 1 33
4 1 1 15
5 1 0 26
6 1 1 25
1 2 0 16
2 2 0 12
3 2 1 53
4 2 1 23
5 2 0 10
6 2 1 29
;

proc sql;
	create table help as
	select *
	      ,mean(Y) as VisitMean
	from have
	group by Group, Visit
	order by Group, Visit, ID;
quit;

title "Panel Overlayed With Line Plots";
proc sgpanel data=help;
	panelby Group;
	vbarparm category=visit response=VisitMean;
	series x=Visit y=y / group=ID markers markerattrs=(symbol=circlefilled);
	rowaxis display=(nolabel) grid;
	colaxis display=(nolabel);
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Use the SERIES Statement to plot your individual IDs and use the VBARPARM instead of VBAR, since SERIES and VBAR cannot be overlayed. 

 

Also check out Plot Type Compatibility for a nice summary of what plot types can be overlayed in PROC SGPLOT

 

 

PeterClemmensen
Tourmaline | Level 20

Be aware though, that with VBARPARM, you have to calculate the mean values beforehand. 

 

Also, provide some sample of your data to get a code answer 🙂

Melk
Lapis Lazuli | Level 10

Sure and thanks!

 

Sample data:

 

ID     Visit     Group     Y

1        1           0         20

2        1           0         24

3        1           1         33

4        1           1         15

5        1           0         26

6        1           1         25

1        2           0         16

2        2           0         12

3        2           1         53

4        2           1         23

5        2           0         10

6        2           1         29

PeterClemmensen
Tourmaline | Level 20

If I understand you correctly, then do something like this

 

data have;
input ID$ Visit Group Y;
datalines;
1 1 0 20
2 1 0 24
3 1 1 33
4 1 1 15
5 1 0 26
6 1 1 25
1 2 0 16
2 2 0 12
3 2 1 53
4 2 1 23
5 2 0 10
6 2 1 29
;

proc sql;
	create table help as
	select *
	      ,mean(Y) as VisitMean
	from have
	group by Group, Visit
	order by Group, Visit, ID;
quit;

title "Panel Overlayed With Line Plots";
proc sgpanel data=help;
	panelby Group;
	vbarparm category=visit response=VisitMean;
	series x=Visit y=y / group=ID markers markerattrs=(symbol=circlefilled);
	rowaxis display=(nolabel) grid;
	colaxis display=(nolabel);
run;
Melk
Lapis Lazuli | Level 10
worked beautifully, thank you!

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!

How to Concatenate Values

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.

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
  • 992 views
  • 1 like
  • 2 in conversation