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.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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