DATA Step, Macro, Functions and more

Concatenate with Carriage Return and special formatting

Reply
Occasional Contributor
Posts: 9

Concatenate with Carriage Return and special formatting

OK, I have a special situation where I am trying to combine 2 fields into a single field with a carriage return and the first line of the output to be bold. For example:

 

Mary Smith

 

123 Main St.  

Anytown USA

 

I am trying to put this output directly to Excel and I have been attempting ODS to make this happen mainly because of the bold function that I need for part of the field.  Can this happen directly in ODS?  or is there a way to concatenate these with a carriage return, then bold only a portion of the field?

 

Thank you all.  

Super User
Posts: 10,681

Re: Concatenate with Carriage Return and special formatting

Posted in reply to Lost_Gary

Use escapechar= and special character  '~n' .

 

ods escapechar='~' ;
...........
x='Mary Smith ~n 123 Main St. ~n Anytown USA ~n';

Occasional Contributor
Posts: 9

Re: Concatenate with Carriage Return and special formatting

Not sure I completely understand how to use the escapechar feature.  Is this used in the dataset or in the proc print of the ods output?  

 

ods escapechar='~';

data new_data;

set old_data;

name_address = name ~n address ~n;

run;

 

or

 

ods escapechar='~';

proc print data old_data;

var x=name ~n address ~n;

run;

 

 I don't seem to be having any luck with trying these methods.  I must be missing something.  

Occasional Contributor
Posts: 9

Re: Concatenate with Carriage Return and special formatting

Posted in reply to Lost_Gary

maybe if i wasn't calling it a carriage return I would have found this post (carriage return - how old am I?):  

 

https://communities.sas.com/t5/Base-SAS-Programming/Adding-a-line-feed-character-when-joining-two-co...

 

so, catx('0a'x,Name,Address) is just about what I was looking for, but How do I bold just the name field as part of this new combined field?  Is that possible?  

Super User
Posts: 13,293

Re: Concatenate with Carriage Return and special formatting

Posted in reply to Lost_Gary

Data set values do not contain any characteristics such as font face, weight, bold, underline or such.

Style attributes can be applied to reporting procedures such as Proc Print, Tabulate, Report or the results of the data step Report Writing Interface.

Or insert raw codes for the destination you are going to use such that the appropriate file viewer will apply the characteristic you want.

 

If you are looking to mix font weight in a single cell of a table perhaps the RWI approach would be best but I can't provide any specific examples other than are in the online documentation.

SAS Super FREQ
Posts: 810

Re: Concatenate with Carriage Return and special formatting

Posted in reply to Lost_Gary

You can use the ODS Inline formatting functions to do this. Unfortunately the ODS EXCEL destination does not seem to honor this, please contact technical support. See the code below for an example. It works allright for PDF and HTML and tagsets.excelxp.

 

ods escapechar="~";
data reportData;  
  set sashelp.class;
  length newColumn newcolum2 $ 64;

  newColumn = cats(
    "~{style [font_weight=bold]", name, "}"
    , "~{newline}"
    , catx(" ", age, sex)
  );

  newColum2 = catx("~{newline}", name, sex, age);
run;

ods excel file="c:\temp\sample.xlsx";
ods pdf file="c:\temp\sample.pdf";
ods tagsets.excelxp file="c:\temp\sample.xml";
proc print data=reportData;
run;
ods tagsets.excelxp close;
ods pdf close;
ods excel close;

 

Ask a Question
Discussion stats
  • 5 replies
  • 130 views
  • 2 likes
  • 4 in conversation