I received the SAS text "Longitudinal Data Analysis with Discrete and Continuous Responses" a couple of days ago. The first sections of the book show how to draw spaghetti plots and add a fitted spline with sgplot. The problem I'm having is when attempting to draw the spaghetti plot by patient ID but then to draw 2 (or more) different splines by a grouping variable.
The book shows the following code, but when I run it I get the error shown. That is, it seems that the group variable cannot be different between the "series" statement and the "pbspline" statement. Can anyone help?
6060 goptions reset=all;
6061 proc sgplot data=sasuser.aids nocycleattrs noautolegend;
6062 series y=cd4 x=time / group=id transparency=0.5
6063 lineattrs=(color=cyan pattern=1);
6064 pbspline y=cd4 x=time / group=drug nomarkers smooth=50 nknots=5
6065 lineattrs=(thickness=3) name="drug";
6066 xaxis values=(-3 to 5.5 by 0.5) label='Years since Seroconversion';
6067 yaxis values=(0 to 3500 by 500) label='CD4 Cell Counts';
6068 keylegend "drug";
6069 format drug druggrp.;
6070 title 'Individual Profiles with Drug Usage Subgroups';
6071 run;
WARNING: Since the group variable on the PBSPLINE statement is different from the first
specified group variable, the group on the PBSPLINE statement will be ignored.
... View more