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

 

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 387 views
  • 0 likes
  • 2 in conversation