BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
js5
Pyrite | Level 9 js5
Pyrite | Level 9

Hello,

 

I have to create a figure equivalent to this one:

proc summary data=sashelp.cars noprint nway;
	var MSRP;
	class Origin DriveTrain;
	output out=cars_summary lclm= uclm= mean= /autoname;
run;

data cars_for_plot;
	set sashelp.cars cars_summary;
run;

proc sgpanel data=cars_for_plot;
	panelby DriveTrain / layout=columnlattice noborder noheader columns=3 skipemptycells sort=ascformat;
	rowaxis type=log label="MSRP";
	colaxis label=" " fitpolicy=rotatealways valuesrotate=vertical discreteorder=formatted;
	keylegend "ssss" / position=right noborder;
	vbarparm category=Origin response=MSRP_Mean / group=DriveTrain groupdisplay=cluster grouporder=ascending baseline=10 datalabel datalabelfitpolicy=none name="ssss";
	highlow x=Origin high=MSRP_UCLM low=MSRP_LCLM / group=DriveTrain highcap=serif lowcap=serif;
	scatter x=Origin y=MSRP / group=DriveTrain jitter markerattrs=(symbol=circlefilled size=5) transparency=0.50 clusterwidth=0.7;
	refline 1e5 / lineattrs=(pattern=shortdash) label="LLOD";
run;

I have received a request to improve two visual aspects:

  • move the refline label outside of the plot so that it is only printed once per row: is this possible with sgpanel?
  • move the vbar labels up so that these do not overlap with error bars and the scatter plot: is this possible?

Thank you for your input in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
proc summary data=sashelp.cars noprint nway;
 var MSRP;
 class Origin DriveTrain;
 output out=cars_summary lclm= uclm= mean= /autoname;
run;

data cars_for_plot;
 set sashelp.cars cars_summary nobs=nobs;
 if _n_ =nobs-2 or _n_= nobs-1 or _n_= nobs then ref=1e5;
    if _n_=nobs then label="LLOD" ;

 if not missing(MSRP_Mean) then y_datalabel=MSRP_Mean+120000;
run;

proc sgpanel data=cars_for_plot;
 panelby DriveTrain / layout=columnlattice noborder noheader columns=3 skipemptycells sort=ascformat;
 rowaxis type=log label="MSRP";
 colaxis label=" " fitpolicy=rotatealways valuesrotate=vertical discreteorder=formatted;
 keylegend "ssss" / position=right noborder;
 vbarparm category=Origin response=MSRP_Mean / group=DriveTrain groupdisplay=cluster grouporder=ascending baseline=10  name="ssss";
    scatter x=Origin y=y_datalabel/markerchar=MSRP_Mean labelstrip;

 highlow x=Origin high=MSRP_UCLM low=MSRP_LCLM / group=DriveTrain highcap=serif lowcap=serif;
 scatter x=Origin y=MSRP / group=DriveTrain jitter markerattrs=(symbol=circlefilled size=5) transparency=0.50 clusterwidth=0.7;
 refline ref / lineattrs=(pattern=shortdash) label=label labelpos=max ;
run;

Ksharp_0-1667993919446.png

 

View solution in original post

1 REPLY 1
Ksharp
Super User
proc summary data=sashelp.cars noprint nway;
 var MSRP;
 class Origin DriveTrain;
 output out=cars_summary lclm= uclm= mean= /autoname;
run;

data cars_for_plot;
 set sashelp.cars cars_summary nobs=nobs;
 if _n_ =nobs-2 or _n_= nobs-1 or _n_= nobs then ref=1e5;
    if _n_=nobs then label="LLOD" ;

 if not missing(MSRP_Mean) then y_datalabel=MSRP_Mean+120000;
run;

proc sgpanel data=cars_for_plot;
 panelby DriveTrain / layout=columnlattice noborder noheader columns=3 skipemptycells sort=ascformat;
 rowaxis type=log label="MSRP";
 colaxis label=" " fitpolicy=rotatealways valuesrotate=vertical discreteorder=formatted;
 keylegend "ssss" / position=right noborder;
 vbarparm category=Origin response=MSRP_Mean / group=DriveTrain groupdisplay=cluster grouporder=ascending baseline=10  name="ssss";
    scatter x=Origin y=y_datalabel/markerchar=MSRP_Mean labelstrip;

 highlow x=Origin high=MSRP_UCLM low=MSRP_LCLM / group=DriveTrain highcap=serif lowcap=serif;
 scatter x=Origin y=MSRP / group=DriveTrain jitter markerattrs=(symbol=circlefilled size=5) transparency=0.50 clusterwidth=0.7;
 refline ref / lineattrs=(pattern=shortdash) label=label labelpos=max ;
run;

Ksharp_0-1667993919446.png

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 719 views
  • 0 likes
  • 2 in conversation