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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.