BookmarkSubscribeRSS Feed
somebody
Lapis Lazuli | Level 10

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? 

3 REPLIES 3
GraphGuy
Meteorite | Level 14

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;

 

female.png

 

male.png

 

somebody
Lapis Lazuli | Level 10

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;
DanH_sas
SAS Super FREQ

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

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 641 views
  • 2 likes
  • 3 in conversation