Is there a way to tell SAS to treat dashed-words as two separate words when determining when to insert a line break? Currently, a 'dashed-word' is treated as a single word and, at the end of the line, line-break is not inserted after the dash--the whole dashed-word is moved to a new line if it does not fit. There must be an option that would tell SAS to leave 'dashed-' at the end of the line and place 'word' on the new line. Currently, I am inserting a space between the dash '-' and the word 'word'.
Thanks,
Haris
Try placing both characters in the SPLITCHAR option.
When I run your code on SAS 9.4 modified as
proc sgplot data=g; vbar Cat / response=Value; xaxis fitpolicy=splitalways splitchar='- ' splitcharnodrop ; run;
each of the labels are displayed as three rows and the dashes are displayed at the end of the split as needed.
What SAS PROC or application (e.g. Visual Analytics) are you doing this in?
Multiple procs. Specifically, I used in PROC SGPLOT as a value label, PROC REPORT as a column header as well as a row header, PROC ODSTEXT, etc. If there are PROCs that support this kind of functionality and others that don't, I'd like to know that too.
EDIT: so, apparently, both PROC PRINT and PROC report do this correctly with text in the cells--they both break a line at the dash. PROC SGPLOT does not break at the dash when labeling values on x axis. I will need to double-check how dash is treated in PROC REPORT column headers.
In PROC REPORT, I myself tell it where to place line breaks in the column headers. I haven't done this in PROC SGPLOT, so that's something you can try yourself.
ods escapechar='^';
proc report data=sashelp.class;
columns name;
define name/group "What is^{newline 1}the Student's^{newline 1}Name?";
run;
I realize that's not exactly the same as what you are asking for, where SAS does the splitting at a hyphen automatically.
Yes, thanks. EscCharacter is what I am using now on an ad hoc basis. But, as you noted, that's not what I need. In my case, what is printed is a format for a numeric value. I need it to work across multiple different deployments. Forcing a line-break is not what I want when it is used as a row header.
Show your 1) proc sgplot code 2) example data and 3) tell us which release of SAS you are using.
Since you say this is for an axis label then the appropriate axis statement can use the SPLITCHAR SPLITCHARNODROP and SPLITJUSTIFY options if using 9.4 (at least) or later. You may have issues related to FITPOLICY if you are attempting to display a lot of values also.
Also there is a potential issue of exactly which "dash" character is in your data versus the code you submit. The "-" on the keyboard for programming may not be an emdash or other word processing/ Unicode character dash in your data.
Thanks Ballardw,
This very close to what I need. I did not know about the SPLITCHARNODROP. Very useful. Only one problem remains: I need the program to treat a *space* as a break as well as the *hyphen* character. I need the labels to split into three lines. Is there a way to specify more than one SPLITCHAR?
I can't rotate the value labels as the y-axis space is at a premium and x-axis categories can be wordy.
data g;
input Cat$ 16. Value;
cards;
OneH-TwoH Three1 4
One Two Three2 3
OneH-TwoH Three3 2
One Two Three4 1
OneH-TwoH Three5 4
One Two Three6 5
OneH-TwoH Three7 2
One Two Three8 3
;
proc sgplot data=g;
vbar Cat / response=Value;
xaxis fitpolicy=splitalways splitchar='-' splitcharnodrop;
run;
Try placing both characters in the SPLITCHAR option.
When I run your code on SAS 9.4 modified as
proc sgplot data=g; vbar Cat / response=Value; xaxis fitpolicy=splitalways splitchar='- ' splitcharnodrop ; run;
each of the labels are displayed as three rows and the dashes are displayed at the end of the split as needed.
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.