BookmarkSubscribeRSS Feed
HitmonTran
Pyrite | Level 9

I have a variable "col1" and I want to split the value into a new line in proc report when there's a "/" because there isn't enough space in the rtf.

Current output:

HitmonTran_0-1619820303717.png

Current code:

data x; 
set y; 
col1= soc ||'/'|| pt; 
run; 

proc report data=final nowindows center headline headskip missing split='@'; 
column col:; 
define col1 / order style(column)={asis=on just=left cellwidth=.8in} flow style(header)={just=left font_size=9pt} "SOC/PT" ;
run; 

 

9 REPLIES 9
ChrisNZ
Tourmaline | Level 20

 

I have a variable "col1" and I want to split the value into a new line in proc report when there's a "/" because there isn't enough space in the rtf.

Current output:

ChrisNZ_0-1619838975529.png

 

Current code:

data x; 
set y; 
col1= soc ||'/'|| pt; 
run; 

proc report data=final nowindows center headline headskip missing split='@'; 
column col:; 
define col1 / order style(column)={asis=on just=left cellwidth=.8in} flow style(header)={just=left font_size=9pt} "SOC/PT" ;
run; 

 

 

Why split='@'   and not   split='/'  if you want to split at / ?

HitmonTran
Pyrite | Level 9
Because I have columns with dates that uses "/". Either way, if i changed
"@" to "/" it doesn't work
Ksharp
Super User
data x; 
set y; 
col1= soc ||' (*ESC*)n '|| pt; 
run; 
Tom
Super User Tom
Super User

SPLIT works fine for plain old text listing output.  But it looks like ODS ignores it.

data final; 
  soc ='AAAA';
  pt='BBBB';
  col1= soc ||'@'|| pt; 
run; 

proc report data=final nowindows center headline headskip missing split='@'; 
column col:; 
define col1 / order style(column)={asis=on just=left cellwidth=.8in} flow style(header)={just=left font_size=9pt} "SOC/PT" ;
run; 

image.pngimage.png

You will need to ODS compatible methods if you want to produce ODS output.

@Ksharp wrote:
data x; 
set y; 
col1= soc ||' (*ESC*)n '|| pt; 
run; 

 

Cynthia_sas
SAS Super FREQ

Hi:
SPLIT= is designed to allow control for splitting strings in column headers, not in data cells. Using the ODS ESCAPECHAR NEWLINE function is the best way to achieve what is needed. However, it will mean using a DATA step to alter the code so that \ turns into ESCAPECHAR + {newline 1} -- there is an older method using just ESCAPECHAR+n, but that is an artifact of the original ESCAPECHAR syntax and it might be better to switch to the newest syntax. Or you could use RTF control strings. Here's an example of all 3 methods.
Cynthia

 

Cynthia_sas_0-1619882075148.png

 

The code for the above examples:

data fakedata; 
  length socpt $70;
  infile datalines dlm=',';
  input rownum socpt $;
  label socpt = 'Soc@PT'
        rownum = 'Row@Number';
return;
datalines;
10, Twas brillig and the slithy toves/did gyre and gimble in the wabe.
11, All mimsy were the borogroves/and the momeraths outgrabe.
;
run;

data newdata;
  length first last $70 newsoc soc2 soc3 $90;
  set fakedata;
  first = scan(socpt,1,'/');
  last = scan(socpt,2,'/');
  newsoc = catx('^{newline 1}',first,last);
  soc2 = catx('^n',first,last);
  soc3 = catx(' \line ',first,last);
run;

options orientation=landscape topmargin=.25in bottommargin=.25in 
        rightmargin=.25in leftmargin=.25in;
ods escapechar='^';
Title; Footnote;
  
ods rtf file='c:\temp\newline_datacell.rtf' startpage=no;
proc report data=newdata split='@';
  column rownum socpt newsoc;
  define rownum / order;
  define socpt / display 'Original@SocPT';
  define newsoc / display 'Soc PT@using new Escapechar';
  compute before _page_/style=Header;
    line 'Using New Escapechar';
  endcomp;
run;
    
proc report data=newdata split='@';
  column rownum socpt soc2;
  define rownum / order;
  define socpt / display 'Original@SocPT';
  define soc2 / display 'Soc PT@using old Escapechar';
  compute before _page_/style=Header;
    line 'Using Old Escapechar';
  endcomp;
run;
  
proc report data=newdata split='@';
  column rownum socpt soc3;
  define rownum / order;
  define socpt / display 'Original@SocPT';
  define soc3 / display 'Soc PT@using RTF control string'
         style(column)={protectspecialchars=off};
  compute before _page_/style=Header;
    line 'Using RTF Control Strings';
  endcomp;
run;
ods rtf close;

 

Tom
Super User Tom
Super User

@Cynthia_sas wrote:

Hi:
SPLIT= is designed to allow control for splitting strings in column headers, not in data cells.

...


Note that is not really a true statement since the SPLIT= option has always worked for splitting content for the listing output.

Perhaps you mean they only implemented the SPLIT= option for headers when they added ODS support?

Cynthia_sas
SAS Super FREQ

Hi, Tom:

  That was the way I remembered it too. But then I tested in 9.4M7 and found something different. Here's my LISTING output using / inside a datacell:

Cynthia_sas_0-1619900452583.png

 

  So I think you're right that it used to work that way in SAS 5 and 6 and even possibly after the formal ODS introduction in 8, but that's not what I could generate today.

 

Cynthia

 

Tom
Super User Tom
Super User

Did they change it in 9.4M7 ?  Because the example I posted above is from 9.4M5 and it definitely split the value on the split character.  

 

You have to use the FLOW option on the column definition in PROC REPORT.

Cynthia_sas
SAS Super FREQ

Tom:

  My bad. You're right. With the FLOW option, the LISTING destination honors the split character:

Cynthia_sas_0-1619980776686.png

 

  But FLOW is a LISTING-only option so, it is ignored for other ODS destinations like RTF, PDF and HTML. What I should have clarified in my original post was:

SPLIT= is designed to allow control for splitting strings in column headers, not in data cells for most ODS destinations like RTF, PDF and HTML. The SPLIT= option can be used in LISTING output for data cells (with the FLOW option in PROC REPORT), but ODS STYLE overrides are not used by the LISTING destination. If you want the data cells to be split in ODS destinations like RTF, PDF and HTML, then the workaround is to use ODS ESCAPECHAR or, for RTF, RTF control strings.

 

  I find fewer students using LISTING output especially when working in SAS Studio with server-based SAS, so thanks for giving me the chance to refresh my LISTING skills.

Cynthia

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 9 replies
  • 10079 views
  • 0 likes
  • 5 in conversation