BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AntjeWestphal
Obsidian | Level 7

Hi!

 

I used XAXISTABLE in PROC SGPLOT to show text values. For variable "Charge" the values overlap.

 

xaxistable.jpg

 

Is it possible to split the values automatically if the space is to small? I couldn't find the solution with VALUEATTRS or FITPOLICY=split.

 

xaxistable Charge Beschichtung Konjugat / location=inside;

 

Best regards

Antje

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

@AntjeWestphal wrote:

To insert the line break after a fixed number of characters sounds good because it's important to see if there is a change in the curves after changing the lot. But can you give me a hint where to insert the floor(length(charge)/2) please? Smiley EmbarassedSmiley Happy In data PF4_2; set PF4_2; format Charge2 $21.; Charge2=floor(length(Charge)/2); run; the results are numbers.


With floor(length(Charge)/2) the line break would not be inserted after a fixed number of characters, but in the middle of the string, more precisely: after 3 characters for strings of lengths 6 or 7, after 4 for lengths 8 and 9, etc. Do you have lot numbers of length 21, as your FORMAT statement suggests? In this case one split might not be enough.

 

/* Example data */

data have;
input Charge $21.;
cards;
WKF2016
017/17I
sehr_lange_Chargennr.
;

/* Split CHARGE values in the middle */

data want(drop=s);
set have;
length Charge2 $23; /* (max. length of CHARGE)+2 */
s=floor(length(charge)/2);
charge2=substr(charge,1,s)||'0D0A'x||substr(charge,s+1);
run;

(Note that the line breaks do not occur in PROC PRINT output.)

 

 

View solution in original post

15 REPLIES 15
PeterClemmensen
Tourmaline | Level 20

Welcome to the SAS community 🙂

 

Can you show us your entire code? What version of SAS do you use?

AntjeWestphal
Obsidian | Level 7

Thank you!

 

SAS-Version: 9.4

 

ods graphics on / width=25cm height=15cm;
options nodate nonumber orientation=landscape topmargin="2.5cm" center;
ods html close;
ods pdf file='Z:\Antje\tempSAS\PF4 QK_07.2018.pdf';
ods layout start; ods region x=0cm y=0cm;
PROC SGPLOT DATA = PF4_2;
styleattrs datacontrastcolors=(blue red green magenta yellow black) WALLCOLOR=LTGRAY
             datasymbols=(x);
   SERIES X = Datum2 Y = MW_IgG_posKontr		/ markers lineattrs=(pattern=solid); 
   SERIES X = Datum2 Y = MW_IgG_negKontr		/ markers lineattrs=(pattern=solid);
   SERIES X = Datum2 Y = MW_IgG_posKontr12verd	/ markers lineattrs=(pattern=solid);
   SERIES X = Datum2 Y = MW_IgG_posKontr14verd	/ markers lineattrs=(pattern=solid);
   SERIES X = Datum2 Y = MW_IgG_posKontr18verd	/ markers lineattrs=(pattern=solid);
   xaxistable Charge Beschichtung2 Konjugat / location=inside;
   keylegend/position=bottom valueattrs=(family=arial) down=10;
   TITLE height=12pt font='arial' 'PF4-Kontrollen IgG Juli 2018';
xaxis label='Juli' labelattrs=(family=arial size=12pt)
valueattrs=(family=arial size=12pt);
yaxis grid gridattrs=(color=black) values=(0 to 3 by 0.5) label='Extinktion' labelattrs=(family=arial size=12pt) valueattrs=(family=arial size=12pt );
where Monat='07/2018'; run;
ods layout end;
ods pdf close;
ods html;
Ksharp
Super User

You could make graph wider by

ods graphics /width=2000px ..............;

 

or change FONTSIZE be smaller ?

AntjeWestphal
Obsidian | Level 7

The graph is already as wide as possible and the font size is really small. Smiley Frustrated

Ksharp
Super User

Unbelievable '0D0A'x could change line .

 

data have;
set sashelp.class;
new_name=catx(' ',name,'0D0A'x,'xxxx');
run;
ods escapechar='~';
proc sgplot data=have(where=(sex='F'));
SERIES X = weight Y = height/ markers lineattrs=(pattern=solid); 
xaxistable new_name / labelattrs=(size=40) location=outside valueattrs=(size=10) ;
run;

x.png

FreelanceReinh
Jade | Level 19

Another option: Use modified Charge values.

 

Example:

Charge='WKF'||'0D0A'x||'2015';

Result:

Charge.png

AntjeWestphal
Obsidian | Level 7

The values of Charge (= lot number) change over time:

 

DB.jpg

FreelanceReinh
Jade | Level 19

@AntjeWestphal wrote:

The values of Charge (= lot number) change over time:

 


As long as there are only a few different patterns (e.g. WKFyyyy and nnn/nnx and perhaps a few more), it should be possible to insert the line break ('0D0A'x) programmatically at a suitable position. In any case one could insert it after a fixed number of characters or, e.g., after floor(length(charge)/2) characters, but I would like to avoid breaks such as WKF2-016.

AntjeWestphal
Obsidian | Level 7

To insert the line break after a fixed number of characters sounds good because it's important to see if there is a change in the curves after changing the lot. But can you give me a hint where to insert the floor(length(charge)/2) please? Smiley EmbarassedSmiley Happy In data PF4_2; set PF4_2; format Charge2 $21.; Charge2=floor(length(Charge)/2); run; the results are numbers.

FreelanceReinh
Jade | Level 19

@AntjeWestphal wrote:

To insert the line break after a fixed number of characters sounds good because it's important to see if there is a change in the curves after changing the lot. But can you give me a hint where to insert the floor(length(charge)/2) please? Smiley EmbarassedSmiley Happy In data PF4_2; set PF4_2; format Charge2 $21.; Charge2=floor(length(Charge)/2); run; the results are numbers.


With floor(length(Charge)/2) the line break would not be inserted after a fixed number of characters, but in the middle of the string, more precisely: after 3 characters for strings of lengths 6 or 7, after 4 for lengths 8 and 9, etc. Do you have lot numbers of length 21, as your FORMAT statement suggests? In this case one split might not be enough.

 

/* Example data */

data have;
input Charge $21.;
cards;
WKF2016
017/17I
sehr_lange_Chargennr.
;

/* Split CHARGE values in the middle */

data want(drop=s);
set have;
length Charge2 $23; /* (max. length of CHARGE)+2 */
s=floor(length(charge)/2);
charge2=substr(charge,1,s)||'0D0A'x||substr(charge,s+1);
run;

(Note that the line breaks do not occur in PROC PRINT output.)

 

 

AntjeWestphal
Obsidian | Level 7

Thank you Reinhard, that works! Smiley Very Happy

I hoped to get an option within the SGPLOT but that's really fine!

SuryaKiran
Meteorite | Level 14

If they are of few values then check class= for xaxistable

image.png

ods graphics / reset=all;
ods graphics / width=4.5in;

proc sgplot data=sashelp.class (where=(age < 13));
scatter x=name y=height;
xaxistable age / class=age title="Student Age" location=inside 
      valueattrs=(color=red) 
      labelattrs=(color=red)
      titleattrs=(color=red) ;
xaxistable weight height / valueattrs=(color=blue);
run;
Thanks,
Suryakiran
AntjeWestphal
Obsidian | Level 7

Thanks for that idea, but it doesn't work on my graph.

Reeza
Super User
Show your code and sample data. XAXIS has two options that control this - FITPOLICY and SPLITCHAR which may also be in XAXISTABLE but it depends on your SAS version - such as 9.4 TS1M5.