BookmarkSubscribeRSS Feed
gx2144
Calcite | Level 5

The orientation of the label in proc sgplot is vertical. How can I change the label into horizontal?

proc sgplot data = baseline;
histogram salary/datalabel;
density salary;
density salary/type= kernal;
keylegend / location=inside position=topright;
run;

 

2 REPLIES 2
gx2144
Calcite | Level 5

gx2144_0-1611884347279.png

 

Ksharp
Super User

It is real uneasy. Maybe somebody could point you a simple solution.

ods select none;
ods output sgplot=sgplot;
proc sgplot data = sashelp.heart;
histogram weight/datalabel ;
density weight;
density weight/type= kernel;
keylegend / location=inside position=topright;
run;
ods select all;

data a;
 set sgplot;
 _BIN_WEIGHT_DATALABELTYPE=BIN_WEIGHT_DATALABELTYPE_Auto__Y+0.5;
 if not missing( BIN_WEIGHT_DATALABELTYPE_Auto__X );
 keep BIN_WEIGHT_DATALABELTYPE_Auto__X BIN_WEIGHT_DATALABELTYPE_Auto__Y BIN_WEIGHT_DATALABELTYPE_Auto_DL
_BIN_WEIGHT_DATALABELTYPE;
 format BIN_WEIGHT_DATALABELTYPE_Auto_DL 8.2;
run;
data b;
 set sgplot;
 if not missing(NORMLD_WEIGHT___X);
 keep NORMLD_WEIGHT___X NORMLD_WEIGHT___Y;
run;
data c;
 set sgplot;
 if not missing(KERNEL_WEIGHT___X) ;
 keep KERNEL_WEIGHT___X KERNEL_WEIGHT___Y;
run;

proc sql;
create table temp as
select a.*,NORMLD_WEIGHT___Y 
 from a,b
  group by BIN_WEIGHT_DATALABELTYPE_Auto__X
   having abs(BIN_WEIGHT_DATALABELTYPE_Auto__X-NORMLD_WEIGHT___X) =
     min(abs(BIN_WEIGHT_DATALABELTYPE_Auto__X-NORMLD_WEIGHT___X));

create table have as
select temp.*,KERNEL_WEIGHT___Y 
 from temp,c
  group by BIN_WEIGHT_DATALABELTYPE_Auto__X
   having abs(BIN_WEIGHT_DATALABELTYPE_Auto__X-KERNEL_WEIGHT___X) =
     min(abs(BIN_WEIGHT_DATALABELTYPE_Auto__X-KERNEL_WEIGHT___X));
quit;


proc sgplot data=have;
vbarparm category= BIN_WEIGHT_DATALABELTYPE_Auto__X response=BIN_WEIGHT_DATALABELTYPE_Auto__Y / barwidth=1 ;
scatter x=BIN_WEIGHT_DATALABELTYPE_Auto__X y=_BIN_WEIGHT_DATALABELTYPE/ 
 markerchar=BIN_WEIGHT_DATALABELTYPE_Auto_DL discreteoffset=-0.1 ;
series x= BIN_WEIGHT_DATALABELTYPE_Auto__X y=NORMLD_WEIGHT___Y /
 name='normal' legendlabel='Normal' smoothconnect lineattrs=graphdata1(thickness=3);
series x= BIN_WEIGHT_DATALABELTYPE_Auto__X y=KERNEL_WEIGHT___Y /
 name='kernel' legendlabel='Kernel' smoothconnect lineattrs=graphdata2(thickness=3);
keylegend 'normal' 'kernel'/position=ne location=inside;
run;

SGPlot29.png

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1014 views
  • 0 likes
  • 2 in conversation