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

Hello,

 

I have this code to put the data I need separated by a comma. Now, what I need is a new line after the comma.

 

Currently, I have this

 

1 due to symptom1,2 due to symptom2,1 due to symptom3,3 due to symptom4,1 due to symptom5, 1 due to symptom6, and so on.. 
 
What I need is 
 
1 due to symptom1,
2 due to symptom12,
1 due to symptom3,
3 due to symptom4,
1 due to symptom5,
1 due to symptom6,
 and so on.. 
 
My code :
 
data want;
length cat $10000;
do until (last.death_onstudy);
set freqs;
by death_onstudy notsorted;
cat=catx(',',cat,death_reason);
end;
run;
 
Please help get each symptom to a new line. Thanks very much in advance!!!
1 ACCEPTED SOLUTION

Accepted Solutions
saslove
Quartz | Level 8

Solution that worked for me:

 

I used ods escapechar='^';

 

I added ^n where I want my line break. It doesn't show in the listing or dataset but t works on the rtf file and html file. 

 cat=catx(',^n',cat,death_reason);

View solution in original post

13 REPLIES 13
ChrisNZ
Tourmaline | Level 20

You can use something like

CAT=catx(','||'0D0A'x, CAT DEATH_REASON);

Where it gets used depends on the output.

You won't see the LF in an HTML report for example.

 

saslove
Quartz | Level 8

Adding the '0D0A'x didn't work for me. I am creating rtf destination, but its all in one big line separated by commas. It doesn't add a line after commas. 

ChrisNZ
Tourmaline | Level 20

If you use proc report, you can insert RTF codes with the ~R prefix.

See here.

ChrisNZ
Tourmaline | Level 20

For example:

data T; 
  A=catx(','||'0d0a'x , 'ABC', 'DEF'); 
run;

Capture.PNG

 

Tom
Super User Tom
Super User

A new line WHERE?  Your code seems to be just creating a character strings, not a report.

saslove
Quartz | Level 8

I need to use it in an ODS RTF destination.

novinosrin
Tourmaline | Level 20

data have;
str='1 due to symptom1,2 due to symptom2,1 due to symptom3,3 due to symptom4,1 due to symptom5, 1 due to symptom6';
run;

data want;
set have;
do _n_=1 to countw(str,',');
want=cats(scan(str,_n_,','),',');
output;
end;
run;
saslove
Quartz | Level 8

Thanks, I need it in the same cell. This puts a new row for each line, but I need everything in one cell. 

Cynthia_sas
Diamond | Level 26

Hi:

  ODS RTF supports the ESCAPECHAR and the {newline} function. In the example below, I declared my ESCAPECHAR to be caret ^, as shown in the code and it produced the same output in both PROC PRINT and PROC REPORT.

use_escapechar_rtf.png

 

Hope this helps,

Cynthia

ChrisNZ
Tourmaline | Level 20

@Cynthia_sas I tried escaping a new line but never found the correct syntax.

I tried \line and \par and even unicode values.

It turns out {newline} does it. 

It's not easy finding the proper syntax.

 

Like the unicode implementation (and here)  I find this confusing.

saslove
Quartz | Level 8

Solution that worked for me:

 

I used ods escapechar='^';

 

I added ^n where I want my line break. It doesn't show in the listing or dataset but t works on the rtf file and html file. 

 cat=catx(',^n',cat,death_reason);

Cynthia_sas
Diamond | Level 26
Hi:
That use of newline ^n is older code which has been replaced by the function-like syntax I showed in my post.
It may be that someday the use of the older ^n will no longer work, so I'd recommend to eventually move to ^{newline 1} so your code is current.
Cynthia
saslove
Quartz | Level 8

Perfect! I just changed my code to ^newline. Thanks so much.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 27590 views
  • 5 likes
  • 5 in conversation