Dear all, I am working with some longitudinal data, where I am making a spaghetti-plot for each patient. I need to "mark" the occurrence of some dates in the plot, and I have thought about doing that with a dummy-variable and use the colourresponse option, but I can't get it to do it right. So, below is a test-dataset containing patientid, visit_date, measurement (measure), age at measure (age_measure), date of diagnosis 1 (dx1), date of diagnosis 2 (dx2). The desired output is a spaghetti-plot with patient id as group, and where the color changes when the visitdate passes the diagnosis date. In the code below I have only made the dummy variable contain diagnosis 1, it would be a great help to show me, how to incorporate the date of diagnosis 2 also. if it helps, I can change the dates to corresponding age_measure values. Thanks 🙂 data patients;
input patientid $ (dx1 dx2) (:yymmdd8.);
format dx1 dx2 yymmdd10.;
datalines;
1 20180101 20180110
2 20170205 .
3 20170221 20170225
4 20180101 20180202
5 . 20180503
;
data visits;
input patientid $ visit_date :yymmdd8. measure age_measure;
format visit_date yymmdd10.;
datalines;
1 20180101 3.4 10
1 20180505 2.3 15
2 20170210 7.3 20
2 20170217 7.2 25
2 20170220 7.1 30
3 20170221 5.4 35
4 20180202 3.4 23
4 20180204 3.2 25
5 20180504 5.6 30
5 20180505 5.0 32
;
data have;
merge
patients
visits
;
by patientid;
run;
/* The plot */
data have;
set have;
If .<dx1 ge age_measure
then dummy_var = 2;
else
If .<dx1 LT age_measure then dummy_var=1;
else dummy_var=.;
run;
proc sgplot data=have noborder subpixel;
series x=age_measure y=measure / group=patientid colorresponse=dummy_var colormodel=(red gold green) lineattrs=(thickness=2);
xaxis display=(noline noticks nolabel) grid;
yaxis display=(noline noticks nolabel) grid;
run;
... View more