BookmarkSubscribeRSS Feed
jenim514
Pyrite | Level 9

Hi all,

 

I need advise for how to wrap a text string to a new line before parenthesis:

 

Variable value looks like this with varying lengths but same value/parenthesis format: 

 

450 mg (450 mg TDD)

 

want output to look like this in output:

450 mg

(450 mg TDD)

 

 

I remember it is something like ~n but not sure how to use it?

 

Thanks!

 

4 REPLIES 4
novinosrin
Tourmaline | Level 20
data want;
k='450 mg (450 mg TDD)';
var=substr(k,1,index(k,'(')-1);
output;
var=substr(k,index(k,'('));
output;
run;

are you read a raw data or dataset? the above works if you are reading a dataset 

jenim514
Pyrite | Level 9

@novinosrin I'm sorry I need to clarify more 🙂

 

I don't need two separate observations but rather I need  same line that will wrap to a new line in a report.  

 

So maybe how can I add the ~n before the '(' ?

k='450 mg ~n (450 mg TDD)';

Reeza
Super User

Is this for a report? I believe the method varies slightly depending on the output destination, you usually use ODS ESCAPECHAR and then SPLIT as well specified within PROC REPORT statement.

 


@jenim514 wrote:

Hi all,

 

I need advise for how to wrap a text string to a new line before parenthesis:

 

Variable value looks like this with varying lengths but same value/parenthesis format: 

 

450 mg (450 mg TDD)

 

want output to look like this in output:

450 mg

(450 mg TDD)

 

 

I remember it is something like ~n but not sure how to use it?

 

Thanks!

 


 

jenim514
Pyrite | Level 9

Ok, I figured it out by just breaking the var into two variables, then inserting the escapechar

 

 

trt1= scan(trt01p,1,'(');
if trt01p ^='Placebo' then trt2=substr(trt01p,index(trt01p,'('));
newtrt= catx ('~n',trt1, trt2);

 

Thanks all!

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
  • 4 replies
  • 4207 views
  • 1 like
  • 3 in conversation