i have the below code that i used to generate a graph. One of the point corresponding to August has more than one text label. this two labels are on topp of each other. how do i show them separately on the graph.
options papersize=A3 orientation=landscape pagesize=250 ;
ods graphics on / width=20in;
ods graphics on /height=8in;
proc sgplot data=data1.ProcessHelp ;
title "Process results";
vbox Clean/ category=month group=ref grouporder=data /*extreme */ name='Cleaned' ;
vbox raw / y2axis category=month group=Ref_point grouporder=data /* extreme*/ boxwidth=0.3 /*datalabel=dates
DATALABELATTRS=(Color=red Family="Arial" Size=8 Style=Italic Weight=Bold)*/
transparency=0.7 fillattrs= (color=darkorange) name='Raws';
TEXT Y=raw X=month TEXT=text/POSITION=top TEXTATTRS = (SIZE=7 COLOR='red');
YAXIS LABEL="Allowed process" labelattrs=(weight=bold) ;
Y2AXIS LABEL="Disallowed process" labelattrs=(weight=bold) ;
refline 10 / lineattrs=(color=Green pattern=dash) legendlabel='Spec1 ' name= 'Prod' ;
refline 15 / lineattrs=(color=red pattern=dash) legendlabel='Spec2 ' name='SANS' ;
keylegend 'Cleaned' 'Raws' / title='Reference points: ' valueattrs=(size=8) titleattrs=(size=8) position=bottom exclude= ("") ;
keylegend 'Prod' 'SANS' /TITLE= 'Limits:' valueattrs=(size=8) titleattrs=(size=8) position=bottom ;
xaxis label='Period' ;
run;
Hi @Zandi
In your SGPLOT procedure, you are using the TEXT statement to display the months. And so all you need to do is essentially use another TEXT statement to show the other date. And you can change the previous TEXT statement to only show one of the values in August 2020.
Please see the example code below. Where, two new columns were generated which have the text values, and then another column was generated so that the other value in August can be positioned higher up on the y-axis.
data processhelp2;
set data1.processhelp;
if dates = '31AUG2020'd then text3 = text;
else text2 = text;
raw2 = raw+5;
run;
options papersize=A3 orientation=landscape pagesize=250 ;
ods graphics on / width=20in;
ods graphics on /height=8in;
proc sgplot data=processhelp2;
title "Process results";
vbox Clean/ category=month group=ref grouporder=data /*extreme */ name='Cleaned' ;
vbox raw / y2axis category=month group=Ref_point grouporder=data /* extreme*/ boxwidth=0.3 /*datalabel=dates
DATALABELATTRS=(Color=red Family="Arial" Size=8 Style=Italic Weight=Bold)*/
transparency=0.7 fillattrs= (color=darkorange) name='Raws';
TEXT Y=raw X=month TEXT=text2/POSITION=top TEXTATTRS = (SIZE=7 COLOR='red');
TEXT Y=raw2 X=month TEXT=text3/POSITION=top TEXTATTRS = (SIZE=7 COLOR='red');
YAXIS LABEL="Allowed process" labelattrs=(weight=bold) ;
Y2AXIS LABEL="Disallowed process" labelattrs=(weight=bold) ;
refline 10 / lineattrs=(color=Green pattern=dash) legendlabel='Spec1 ' name= 'Prod' ;
refline 15 / lineattrs=(color=red pattern=dash) legendlabel='Spec2 ' name='SANS' ;
keylegend 'Cleaned' 'Raws' / title='Reference points: ' valueattrs=(size=8) titleattrs=(size=8) position=bottom exclude= ("") ;
keylegend 'Prod' 'SANS' /TITLE= 'Limits:' valueattrs=(size=8) titleattrs=(size=8) position=bottom ;
xaxis label='Period' ;
run;
Hi @Zandi
In your SGPLOT procedure, you are using the TEXT statement to display the months. And so all you need to do is essentially use another TEXT statement to show the other date. And you can change the previous TEXT statement to only show one of the values in August 2020.
Please see the example code below. Where, two new columns were generated which have the text values, and then another column was generated so that the other value in August can be positioned higher up on the y-axis.
data processhelp2;
set data1.processhelp;
if dates = '31AUG2020'd then text3 = text;
else text2 = text;
raw2 = raw+5;
run;
options papersize=A3 orientation=landscape pagesize=250 ;
ods graphics on / width=20in;
ods graphics on /height=8in;
proc sgplot data=processhelp2;
title "Process results";
vbox Clean/ category=month group=ref grouporder=data /*extreme */ name='Cleaned' ;
vbox raw / y2axis category=month group=Ref_point grouporder=data /* extreme*/ boxwidth=0.3 /*datalabel=dates
DATALABELATTRS=(Color=red Family="Arial" Size=8 Style=Italic Weight=Bold)*/
transparency=0.7 fillattrs= (color=darkorange) name='Raws';
TEXT Y=raw X=month TEXT=text2/POSITION=top TEXTATTRS = (SIZE=7 COLOR='red');
TEXT Y=raw2 X=month TEXT=text3/POSITION=top TEXTATTRS = (SIZE=7 COLOR='red');
YAXIS LABEL="Allowed process" labelattrs=(weight=bold) ;
Y2AXIS LABEL="Disallowed process" labelattrs=(weight=bold) ;
refline 10 / lineattrs=(color=Green pattern=dash) legendlabel='Spec1 ' name= 'Prod' ;
refline 15 / lineattrs=(color=red pattern=dash) legendlabel='Spec2 ' name='SANS' ;
keylegend 'Cleaned' 'Raws' / title='Reference points: ' valueattrs=(size=8) titleattrs=(size=8) position=bottom exclude= ("") ;
keylegend 'Prod' 'SANS' /TITLE= 'Limits:' valueattrs=(size=8) titleattrs=(size=8) position=bottom ;
xaxis label='Period' ;
run;
@djrisks The solution worked perfectly. Thank you
@Zandi, you're welcome! That's great!
The solution given requires that one manually check the field 'text' to identify the other 'text' value, I have then modified it to check it through a code. however I am thing of a situation where there is more than one text value, how does one identify them through a code.
Thank you.
data processhelp2;
set data1.processhelp;
by dates;
if first.dates and month = lag(month) and lag(text) ne ' ' then text3 = text;
else if first.dates and text3=' ' then text2 = text;
raw2 = raw+5;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.