Reputation: 231
I'm making a graph using proc SGPANEL in SAS. It is animal data, so it's paneled by animal. In each animal's graph there are 3 lines representing different blood test values. I would like to know if I can control the color such that if the value goes out of normal limits (identified by a separate flag variable), then the data point would be red, but if the value is within normal limits the data point would be black.
I've done similar plots for just a single blood test and in that case I've presented a reference line for normal limits. The problem with this case is that each blood test has different normal limits so I can't use that strategy.
My existing code (which doesn't incorporate the color linking with the flag variable, it just presents the data) is as follows:
proc sgpanel data=all;
panelby animal / spacing=5 novarname columns=5;
series x=dy y=value/ group=parameter markers;
colaxis label='Day';
rowaxis label='Value';
run;
Upvotes: 1
Views: 1895
Reputation: 63424
One way to accomplish this is to overlay your markers with new markers that only exist when the flag is set. Here's an example. Basically I add a new value value_outrange
which only has a value when you want a red marker, then I ask for a scatterplot with it and red marker color.
You could also have all of the markers be overlaid in two scatterplots, one with value_outrange and one with value_inrange, which avoids two markers being in these locations; all in all it doesn't look bad though so I think just the one is fine.
data all;
input animal $ dy value flag parameter;
if flag=1 then value_outrange=value;
else call missing(value_outrange);
datalines;
bear 1 5 0 1
bear 2 6 0 1
bear 3 7 0 1
bear 4 8 0 1
bear 5 13 1 1
bear 6 10 0 1
dog 1 8 0 2
dog 2 9 0 2
dog 3 9 0 2
dog 4 11 1 3
dog 5 10 0 3
dog 6 11 0 3
;;;;
run;
proc sgpanel data=all;
panelby animal / spacing=5 novarname columns=5;
series x=dy y=value/ group=parameter markers;
scatter x=dy y=value_outrange/group=parameter markerattrs=(color=red);
colaxis label='Day';
rowaxis label='Value';
run;
Upvotes: 1