Is there a way to dynamically change the reference line by group? I know the BY command to draw a graph for each group but what about in each of those graphs, we have a different refline too?
Here's one way to do it, by adding some extra obsns to the dataset ...
proc sql noprint;
create table avg_data as
select unique sex, avg(height) as avg_height
from my_data
group by sex;
quit; run;
data my_data; set sashelp.class avg_data;
run;
proc sort data=my_data out=my_data;
by sex;
run;
title "Class Data";
proc sgplot data=my_data uniform=scale;
by sex;
scatter y=height x=weight;
refline avg_height / label;
run;
thanks. This works very well, except that I have 2 reflines which are dates. Instead of date, I would want to label it 'IN' and 'OUT' for the first and second refline, respectively. How could I achieve this? I tried this code but it does not work:
proc sgplot data=Sp500_in_out_sample2;
by stock;
series x=date y=price;
refline date_in / axis=x label='in';
refline date_out/ axis=x label='out';
run;
When you use variable-based REFLINEs, the LABELs must also be variable-based. Just create additional columns containing your "in" and "out" labels (e.g. inlabel and outlabel), and do the following:
proc sgplot data=Sp500_in_out_sample2;
by stock;
series x=date y=price;
refline date_in / axis=x label=inlabel;
refline date_out/ axis=x label=outlabel;
run;
Hope this helps!
Dan
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: