BookmarkSubscribeRSS Feed
svmtho
Calcite | Level 5

Hello,

I have 200 character length observation and I wanted to insert escape character every 30 characters so I can break the text into multiple lines in the report to look better. I am not sure how to get it. Could someone please help me?

 

Thanks,

Svm 

13 REPLIES 13
Reeza
Super User
I believe it is going to depend on your output. What destination are you using, Excel, RTF, PowerPoint, PDF?
svmtho
Calcite | Level 5

I am using PDF Reeza.

ballardw
Super User

The proper character(s) may vary depending on the destination of the output and possibly the procedure used. So, which output destination are you using and what code are you using to create the report?

Example data may help as well.

Note that "inserting" characters may fail at a point because adding characters may make the length exceed the defined length of the variable an so would result in truncating (removing) the right most characters of your original variable.

svmtho
Calcite | Level 5

Here is the code.

ods listing close;

ods escapechar ="~" ;

ods pdf file="H:\Summary report.pdf" bookmarkgen=no;

proc report data=_all_report headline headskip nowd ;

title1 "AD Summary";

column title count pg;

define title / " " display style(column)={width=3.5in};

define count / " " display style(column)={width=6.5in};

define pg / order noprint;

BREAK AFTER pg/page;

run;

ods pdf close;

Tom
Super User Tom
Super User

SAS should wrap the text for you automatically in a PDF file.

I made a sample dataset for your report and ran it via SAS/Studio that automatically produces PDF output file.

data have;
 pg=1;
 legnth title $200 ;
 title=repeat('1234567890',19);
 count=1;
run;

proc report data=have headline headskip nowd ;
  title1 "AD Summary";
  column title count pg;
  define title / " " display style(column)={width=3.5in};
  define count / " " display style(column)={width=6.5in};
  define pg / order noprint;
  BREAK AFTER pg/page;
run;

image.png

If the text has spaces in it then they will be used help make the splits clearer.

ballardw
Super User

@svmtho wrote:

Here is the code.

ods listing close;

ods escapechar ="~" ;

ods pdf file="H:\Summary report.pdf" bookmarkgen=no;

proc report data=_all_report headline headskip nowd ;

title1 "AD Summary";

column title count pg;

define title / " " display style(column)={width=3.5in};

define count / " " display style(column)={width=6.5in};

define pg / order noprint;

BREAK AFTER pg/page;

run;

ods pdf close;


Now WHICH variable is the one you want to insert characters into?

svmtho
Calcite | Level 5

I want to insert the characters in count variable. The issue I was seeing is the text is getting over the border line. 

 

test.JPG

 

 

mkeintz
PROC Star

Are there no internal blanks in your text?   That's how your image looks.   Would it be ok to change all occurrences of a comma with a comma followed by a blank?   Then the automatic text wrap in PDF might be more likely to avoid writing over the cell boundary.  You wouldn't have to put escape characters at fixed intervals, allowing more appealing line wraps for proportional fonts.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
svmtho
Calcite | Level 5

I tired to insert space after comma but it wasn't' successful.  PFAtest.JPG

Reeza
Super User
Please show what you tried. That will likely fix the issue. Are you using CATX() or || to build the variable? CATX will include the space.
svmtho
Calcite | Level 5

I am creating the list using sql into separated by ", "  and resolving it in a data step.

Reeza
Super User

Post your code. If you had a space in the separator it would not occur. 

 


@svmtho wrote:

I am creating the list using sql into separated by ", "  and resolving it in a data step.


 

svmtho
Calcite | Level 5

here is the sample code and data which is kind of similar to my data.

 

proc sql noprint;

select key into:abc separated by ", " from sashelp.aacomp;

quit;

data _All_report;

title="This is a test";

count="&abc.";

run;

 

 

ods listing close;

ods escapechar ="~" ;

ods pdf file="H:\Summary.pdf" bookmarkgen=no;

proc report data=_all_report headline headskip nowd ;

title1 "Summary";

column title count ;

define title / " " display style(column)={width=3.5in};

define count / " " display style(column)={width=6.5in};

run;

ods pdf close;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 13 replies
  • 3792 views
  • 0 likes
  • 5 in conversation