Reputation: 1
I am using PROC SGPANEL to separate the data for the 2 groups, male and female. I need to have the scatter plot showing all subjects data points and the average value plot. I need to combine the graphs together, so the scatter plot and mean line are on the same plot. My data
DATA PROYDATA;
INPUT GROUP ID AGE8 AGE10 AGE12 AGE14 @@;
CARDS;
1 1 26.0 25.0 29.0 31.0 1 2 21.5 22.5 23.0 26.5 1 3 23.0 22.5 24.0 27.5
1 4 25.5 27.5 26.5 27.0 1 5 20.0 23.5 22.5 26.0 1 6 24.5 25.5 27.0 28.5
1 7 22.0 22.0 24.5 26.5 1 8 24.0 21.5 24.5 25.5 1 9 23.0 20.5 31.0 26.0
1 10 27.5 28.0 31.0 31.5 1 11 23.0 23.0 23.5 25.0 1 12 21.5 23.5 24.0 28.0
1 13 17.0 24.5 26.0 29.5 1 14 22.5 25.5 25.5 26.0 1 15 23.0 24.5 26.0 30.0
1 16 22.0 21.5 23.5 25.0
2 1 21.0 20.0 21.5 23.0 2 2 21.0 21.5 24.0 25.5 2 3 20.5 24.0 24.5 26.0
2 4 23.5 24.5 25.0 26.5 2 5 21.5 23.0 22.5 23.5 2 6 20.0 21.0 21.0 22.5
2 7 21.5 22.5 23.0 25.0 2 8 23.0 23.0 23.5 24.0 2 9 20.0 21.0 22.0 21.5
2 10 16.5 19.0 19.0 19.5 2 11 24.5 25.0 28.0 28.0
RUN;
/* set up the data in univariate format */
DATA Unidata;
SET Proydata;
ARRAY AgeVector(4) Age8--Age14;
Subject + 1;
DO Time = 1 TO 4;
Age = 2*Time + 6;
Dental = AgeVector(Time);
OUTPUT;
END;
DROP Age8--Age14;
RUN;
* get a sorted dataset by Group and Age;
DATA SortData;
SET Unidata;
PROC SORT;
BY GROUP Age;
RUN;
This is what I used for the two plots, and I would like for the plots to be separated by group.
PROC SGPANEL NOAUTOLEGEND DATA=Unidata;
PANELBY GROUP;
* observed trends;
SERIES X=Age Y=Dental / GROUP = Subject LINEATTRS = (THICKNESS=1);
FORMAT GROUP GROUP.;
PROC SGPANEL DATA=Sortdata;
PANELBY GROUP;
* mean trends;
VLINE Age /RESPONSE=Dental STAT=MEAN
GROUP=GROUP LINEATTRS=(THICKNESS=2) MARKERS MARKERATTRS=(SIZE=2MM) DATALABEL;
FORMAT GROUP GROUP.;
RUN;
Here is my output enter image description here How can I easily combine these 2 plots?
Upvotes: 0
Views: 762
Reputation: 27508
From Help
The VLINE statement can be combined only with other categorization plot statements in the SGPANEL procedure.
Thus, you can't combine VLINE and SERIES.
What you can do is precompute the MEAN stat for each group+age combination in the plot data and use that in a second SERIES.
Example:
Continuing from you data input and transformation...
proc format;
value group 1='Group A' 2='Group B';
run;
* precompute the mean and automerge with lowest id in the group;
* if automerge to every record in the group the mean series would be messed up;
proc sql;
create table plotdata as
select
*
, case when id=min(id) then mean(dental) else . end as dental_mean
from unidata
group by group, age
order by group, age, id
;
PROC SGPANEL NOAUTOLEGEND DATA=plotdata;
PANELBY GROUP;
* one line per subject;
SERIES X=Age Y=Dental
/ GROUP = Subject
LINEATTRS = (THICKNESS=1)
;
SERIES X=Age Y=Dental_mean /* separate series for the precomputed mean */
/ LINEATTRS=(THICKNESS=2)
MARKERS MARKERATTRS=(SIZE=2MM)
DATALABEL
;
FORMAT GROUP GROUP.;
run;
A cleaner visualization is a VBOX plot.
PROC SGPANEL NOAUTOLEGEND DATA=plotdata;
PANELBY GROUP;
VBOX Dental / group=group category=age ;
FORMAT GROUP GROUP.;
run;
Upvotes: 0
Reputation: 56
Perhaps you are looking for something like this?
PROC MEANS data = sortdata noprint;
by group age;
var Dental ;
output out=meanDental(keep=group age MeanDental) mean=MeanDental;
run;
DATA combined;
merge sortdata meanDental;
by group age;
run;
PROC SGPANEL NOAUTOLEGEND DATA=combined;
PANELBY GROUP;
SERIES X=Age Y=Dental / GROUP = Subject LINEATTRS = (THICKNESS=1);
SERIES X=Age Y=MeanDental / GROUP = Subject LINEATTRS = (THICKNESS=5);
FORMAT GROUP GROUP.;
run;
Upvotes: 0