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
group by sex;
data my_data; set sashelp.class avg_data;
proc sort data=my_data out=my_data;
title "Class Data";
proc sgplot data=my_data uniform=scale;
scatter y=height x=weight;
refline avg_height / label;
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!
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.