Hello, I am using proc sgpanel to plot encounters over time for 2 variables (disease rates) across 4 groups (hospitals). Each hospital has a different date for when they switch health records, which I've stored in the variable 'mgen_date'. The reference line shows up fine, but I can't figure how to apply a label to it. When I try the code below it doesn't apply the label and gives the warning: "
proc sgpanel data=XXXX;
where fisc_monyr >= '01Nov2015'd;
panelby hotel / layout=rowlattice onepanel
novarname uniscale=column;
series x=fisc_monyr y=xxx / legendlabel='Any XXX' lineattrs=(color=black);
series x=fisc_monyr y=yyy / legendlabel='YYY XXX' lineattrs=(color=crimson);
colaxis grid
values=('01Nov2015'd to '01Oct2021'd)
label="Month-Year"
display=all interval=semiyear valuesrotate=diagonal notimesplit;
rowaxis grid
label="Cars per month";
format fisc_monyr monyy..;
/*Add refline for tanker date*/
refline tanker_date / axis=x label="Mardi Gras Start" lineattrs=(color=gray
pattern=shortDash
thickness=1)
transparency=0.1;
run;NOTE: CURVELABEL='MGEN Start' is invalid. The option value cannot be a string when a column of reference lines is plotted. The label will not be drawn."
Here is the graph:
I also have questions about how to format the x-axis, but I'll save that for later. Thanks so much!
Ben
Per the documentation of the REFLINE statement for SGpanel:
a text string for the label value.
| Restriction | The label string does not apply when a variable is used for the REFLINE value. In that situation, the label string is ignored and a message is written to the log. |
If you want to add other text then you could add a variable to the data set to use as the Label= variable in the refline. That value could be different for each Panelby value. One way:
data plotclass;
set sashelp.class;
if sex='F' then do;
refage=12;
reflabel='Female Refline';
end;
else do;
refage=13;
reflabel='Male reference';
end;
run;
proc sgpanel data=plotclass;
panelby sex;
scatter x=age y=weight;
refline refage /axis=x label=reflabel;
run;
Per the documentation of the REFLINE statement for SGpanel:
a text string for the label value.
| Restriction | The label string does not apply when a variable is used for the REFLINE value. In that situation, the label string is ignored and a message is written to the log. |
If you want to add other text then you could add a variable to the data set to use as the Label= variable in the refline. That value could be different for each Panelby value. One way:
data plotclass;
set sashelp.class;
if sex='F' then do;
refage=12;
reflabel='Female Refline';
end;
else do;
refage=13;
reflabel='Male reference';
end;
run;
proc sgpanel data=plotclass;
panelby sex;
scatter x=age y=weight;
refline refage /axis=x label=reflabel;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.