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

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.    

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

3 REPLIES 3
ballardw
Super User

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.

Cynthia_sas
SAS Super FREQ

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;

twildone
Pyrite | Level 9

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2394 views
  • 3 likes
  • 3 in conversation