DATA Step, Macro, Functions and more

join three variables, print to new line with a backslash

Accepted Solution Solved
Reply
Regular Contributor
Posts: 182
Accepted Solution

join three variables, print to new line with a backslash

[ Edited ]

Hi!

 

I have three variables, that need to be joined to one variable and output to new line separate by backslash.  Sorry...so weird to explain!!

 

 

I tried:

 

data final1;
length class $300.;
set final;

class=sys||'/'||'~n/'||hiterm||'/'||'~n/'|| lowterm;

run;

 

proc print data=final1;
run;

 

I need to one variable 'class' with concatenated values of sys, hiterm,lowterm on unique line when '/' encountered:

 

CLASS

sys/

hiterm/

lowterm

 

or sample data output

 

CLASS

Investigation/

Metabolism/

Hyperglycemia

 

 


Accepted Solutions
Solution
‎01-30-2018 02:18 PM
SAS Super FREQ
Posts: 9,329

Re: join three variables, print to new line with a backslash

[ Edited ]

Hi:
You only show one statement. You don't show the rest of your code. Are you using PROC PRINT, PROC REPORT??

You don't show any ODS statement -- I guess that you are using ODS because ~n is the old ESCAPECHAR way of inserting a new line into a text string to show line breaks in ODS HTML, RTF or PDF output. But not all destinations use ESCAPECHAR, so it would be useful to see more code.

 

  Here's an ODS HTML example using the new ESCAPECHAR syntax and showing the output:

example.png

Cynthia

View solution in original post


All Replies
Solution
‎01-30-2018 02:18 PM
SAS Super FREQ
Posts: 9,329

Re: join three variables, print to new line with a backslash

[ Edited ]

Hi:
You only show one statement. You don't show the rest of your code. Are you using PROC PRINT, PROC REPORT??

You don't show any ODS statement -- I guess that you are using ODS because ~n is the old ESCAPECHAR way of inserting a new line into a text string to show line breaks in ODS HTML, RTF or PDF output. But not all destinations use ESCAPECHAR, so it would be useful to see more code.

 

  Here's an ODS HTML example using the new ESCAPECHAR syntax and showing the output:

example.png

Cynthia

Super User
Posts: 23,365

Re: join three variables, print to new line with a backslash

Use CATX instead to concatenate the variables together, it's cleaner and easier to follow.

Super User
Posts: 10,700

Re: join three variables, print to new line with a backslash

class=sys||'/'||'0D0A'x||hiterm||'/'||'0D0A'x|| lowterm;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 126 views
  • 0 likes
  • 4 in conversation