The SAS Output Delivery System and reporting techniques

Re: Splitting Word in Output

Accepted Solution Solved
Reply
Regular Contributor
Posts: 221
Accepted Solution

Re: Splitting Word in Output

Hi....I am trying to insert a statement in a report and the result is having a word split when it has to start a new line. Is there any way of preventing this. Thanks,

DATA _NULL_;

FILE PRINT;

PUT "A query for the Sales History for &Customer with Customer_ID: &CustomerID for the period &fromdate to &todate has revealed that no purchases have been made by this customer during this time period.";

END;

RUN; 

OUTPUT:

A query for the Sales History for James_Mars with Cutomer_ID: 112232784 for the period 20140101 to 20150531 has revealed tha

         t no purchases have been made by this customer during this time period.    


Accepted Solutions
Solution
‎06-28-2015 10:40 AM
SAS Super FREQ
Posts: 8,641

Re: Splitting Word in Output

Hi:

  To add to the suggestion of ODS TEXT=, if you want to control the placement of the line breaks or "line feeds", you can use ODS ESCAPECHAR with the {NEWLINE} function, as shown here:

      

  show_text.png

produced by the code below. I typically use long text strings for inserted text and so I put the text itself into a series of macro variables, which separates the string from the place where the string is used and avoids any issues on some operating systems of programs with quoted text strings wrapping on multiple lines in the program editor. I also like to put my last trailing space into a %str( ) which seems to avoid the issue that occurs sometimes when trailing blanks are suppressed. STARTPAGE=NO is necessary in PDF and RTF, if you want the TEXT To appear immediately before or after the output and not appear on the next page.
      

Cynthia

%let customer= Kermit The Frog;
%let customerID = 123_SS;
%let fromdate = 10Nov1969;
%let todate = %sysfunc(propcase(&sysdate9));

%let part1 = A query for the Sales History for &Customer with Customer_ID: &CustomerID for%str( );
%let part2 = the period &fromdate to &todate has revealed that no purchases have been made by this%str( );
%let part3 = customer during this time period.%str( ) ;
%let part4 = Because it is not easy being green, Kermit does not have any credit cards.;

ods escapechar='^';

 

ods html file='c:\temp\showtext_1.html';
ods pdf file='c:\temp\showtext_1.pdf' startpage=no;
ods rtf file='c:\temp\showtext_1.rtf' startpage=no;

 
proc print data=sashelp.class(obs=3);
  title '1) Example with ODS TEXT';
run;

 

ods text="1) &part1.&part2.&part3.&part4";
ods text="^{newline 3}2) &part4^{newline 3}&part1.&part2.&part3";

ods _all_ close;

View solution in original post


All Replies
Grand Advisor
Posts: 9,681

Re: Splitting Word in Output

PUT is not very smart and likely something like the file default number of columns is going on. Check your LINESIZE setting, if it is around 124 that's a likely cause.

If I were attempting this with Put statements I would break them up to use no more than 80 columns of text per PUT but that could have other issues with margins not aligning with other bits.

If this is part of a longer program I would try instead:

ODS text="A query for the Sales History for &Customer with Customer_ID: &CustomerID for

the period &fromdate to &todate has revealed that no purchases have been made by this

customer during this time period.";

Note there is an intentional space at the beginning of each of the second and third lines of text. The ODS parser, for lack of a better name tends to combine the last work of the previous line with the first of subsequent without that space in my experience. Note that will likely get warnings about "current line length has exceeded ... may have unbalanced quotes".

The ODS text has the advantage that it usually wraps lines as the target destination displays them. For RTF or PDF that means usually a word boundary break and for html then the text wrap changes with displayed width of the page.

Solution
‎06-28-2015 10:40 AM
SAS Super FREQ
Posts: 8,641

Re: Splitting Word in Output

Hi:

  To add to the suggestion of ODS TEXT=, if you want to control the placement of the line breaks or "line feeds", you can use ODS ESCAPECHAR with the {NEWLINE} function, as shown here:

      

  show_text.png

produced by the code below. I typically use long text strings for inserted text and so I put the text itself into a series of macro variables, which separates the string from the place where the string is used and avoids any issues on some operating systems of programs with quoted text strings wrapping on multiple lines in the program editor. I also like to put my last trailing space into a %str( ) which seems to avoid the issue that occurs sometimes when trailing blanks are suppressed. STARTPAGE=NO is necessary in PDF and RTF, if you want the TEXT To appear immediately before or after the output and not appear on the next page.
      

Cynthia

%let customer= Kermit The Frog;
%let customerID = 123_SS;
%let fromdate = 10Nov1969;
%let todate = %sysfunc(propcase(&sysdate9));

%let part1 = A query for the Sales History for &Customer with Customer_ID: &CustomerID for%str( );
%let part2 = the period &fromdate to &todate has revealed that no purchases have been made by this%str( );
%let part3 = customer during this time period.%str( ) ;
%let part4 = Because it is not easy being green, Kermit does not have any credit cards.;

ods escapechar='^';

 

ods html file='c:\temp\showtext_1.html';
ods pdf file='c:\temp\showtext_1.pdf' startpage=no;
ods rtf file='c:\temp\showtext_1.rtf' startpage=no;

 
proc print data=sashelp.class(obs=3);
  title '1) Example with ODS TEXT';
run;

 

ods text="1) &part1.&part2.&part3.&part4";
ods text="^{newline 3}2) &part4^{newline 3}&part1.&part2.&part3";

ods _all_ close;

Regular Contributor
Posts: 221

Re: Splitting Word in Output

Thanks Ballardw & Cynthia.....your help and suggestions were very informative and helpful....

Post a Question
Discussion Stats
  • 3 replies
  • 417 views
  • 3 likes
  • 3 in conversation