Hi, please let me know if anyone knows how to do the following.
I am combining 2 variables (Variable1 and Variable2) and creating a new variable. I am using this New variable in generating RTF file.
How can I make part of this New variable (Variable 2) in BOLD in the RTF file?
New Variable= Variable1+ Variable 2
Try this:
* Close all open ODS destinations;
ods _all_ close;
* Create the sample data;
data work.class;
set sashelp.class;
length agesex $100;
agesex = strip(put(age, best.)) ||
'^{style [font_weight=bold]' || strip(sex) || '}';
run;
* Define the escape character;
ods escapechar='^';
* Create the output using various destinations;
ods html file='test.html' path='C:\temp';
ods pdf file='C:\temp\test.pdf';
ods rtf file='C:\temp\test.rtf';
ods Excel file='C:\temp\test.xlsx';
proc print data=work.class;
var agesex;
run; quit;
ods _all_ close;
Vince DelGobbo
SAS R&D
Does this give you the desired result?
* Close all open ODS destinations;
ods _all_ close;
* Create the sample data;
data work.test;
new_variable = 'This text is normal weight ' ||
'^{style [font_weight=bold]and this text is bold}';
run;
* Define the escape character;
ods escapechar='^';
* Create the output using various destinations;
ods html file='test.html' path='C:\temp';
ods pdf file='C:\temp\test.pdf';
ods rtf file='C:\temp\test.rtf';
ods Excel file='C:\temp\test.xlsx';
proc print data=work.test; run; quit;
ods _all_ close;
Vince DelGobbo
SAS R&D
Thanks Vince.
It's not working for my scenario. The variable is not resolving in the RTF file, it's just printing the variable name.
For ex: I am combining AGE and SEX variables and creating new variable AGESEX. When I generate an RTF file, I want SEX part in BOLD and age in normal font.
When I used your code to generate RTF, instead of printing the values of SEX (Male or Female), it was printed as SEX in BOLD.
EX:
SUBJECT AGESEX
1 43SEX
2 23SEX
3 32SEX
Try this:
* Close all open ODS destinations;
ods _all_ close;
* Create the sample data;
data work.class;
set sashelp.class;
length agesex $100;
agesex = strip(put(age, best.)) ||
'^{style [font_weight=bold]' || strip(sex) || '}';
run;
* Define the escape character;
ods escapechar='^';
* Create the output using various destinations;
ods html file='test.html' path='C:\temp';
ods pdf file='C:\temp\test.pdf';
ods rtf file='C:\temp\test.rtf';
ods Excel file='C:\temp\test.xlsx';
proc print data=work.class;
var agesex;
run; quit;
ods _all_ close;
Vince DelGobbo
SAS R&D
Thanks so much vince_sas. It's working.
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: