How to produce .rtf output with full colors in SAS?

1.4k Views Asked by At

I have made graphics using ODS and SGPLOT in SAS, my code looks like this:

ods rtf file="D:\" style=journal bodytitle nogfootnote;
goptions reset=all;
ods graphics / border=off width=18cm height=8cm ;
ods graphics / border=off width=17cm height=8.5cm;

footnote1 "Program: ";

PROC SGPLOT data=data  noautolegend;
...
keylegend / title="Group:";

run;

ods rtf close;

I am using colors but the output .rtf file is black and white, How can I make it colored?

2

There are 2 best solutions below

0
On

There's nothing in your code to indicate that the graph should have colours. If you specify the colours in PROC SGPLOT they are honoured and override the Style. The STYLE you've chosen is Journal, which is designed for print journals (eons ago) and do not include colour by design.

This shows the difference, where the first graph comes out with colours and the second does not and assumes the default style for Journal.

As another user pointed out, you can choose a different style and get automatic colours, but they're the template colours and not what you choose. There are various methods for specifying color within SGPLOT, the approach used here is a bit of overkill but its the documentation example so easy to use and copy/paste. This is a method typically used to ensure that items are coloured similar across multiple graphs even when possibly missing values, because SAS cycles the colours sequentially regardless of the groups/missing.

data fruit_sales;
input Fruit $ Sales;
datalines;
Apples   40
Pears    25
Oranges  50
Grapes   30
Bananas  60
run;

data attrmapfruit;
retain linecolor "black";
input id $ value $ fillcolor $;
datalines;
fruit Apples  red
fruit Pears   green
fruit Oranges orange
fruit Grapes  purple
fruit Bananas yellow
;
run;


ods rtf file='/folders/myfolders/demo.rtf' style=journal;

title  "Fruit Sales V01 - color";
proc sgplot data=fruit_sales dattrmap=attrmapfruit;
vbar Fruit / response=Sales group=Fruit attrid=fruit;
run;
title;

title  "Fruit Sales V02 - no formats";
proc sgplot data=fruit_sales;
vbar Fruit / response=Sales group=Fruit ;
run;
title;

ods rtf close;
1
On

The color definitions in the journal style are shades of grey.

Use a different style. STYLE=RTF is probably ok.

filename myrtf "%sysfunc(pathname(work))\workers.rtf";

ods rtf file=myrtf style=rtf bodytitle nogfootnote;
goptions reset=all;
ods graphics / border=off width=18cm height=8cm ;
ods graphics / border=off width=17cm height=8.5cm;

footnote1 "Program: ";

PROC SGPLOT data=sashelp.workers  noautolegend;
  series x=date y=electric;
  series x=date y=masonry;
run;

ods rtf close;

You can browse style sources:

  • Interactively
    • right click on root of results tree → Templates → Sashelp.TmplMst → Styles → Journal
  • Programmatically

    proc template;
      source styles.journal;
    run;
    

The LOG will show all the graphic color definitions

define style Styles.Journal;
   parent = styles.default;
   . . .    
   class GraphColors /
      'goffill' = cx666666
      'gofill' = cxf6f6f6
      'govbline' = cx848b93
      'gobline' = cx848b93
      'gncdata12' = cx000000
      'gncdata11' = cx000000
      'gncdata10' = cx000000
      'gncdata9' = cx000000
      'gncdata8' = cx000000
      'gncdata7' = cx000000
      'gncdata6' = cx000000
      'gncdata5' = cx000000
      'gncdata4' = cx000000
      'gncdata3' = cx000000
      'gncdata2' = cx000000
      'gncdata1' = cx000000
      'gncdata' = cx000000
      'gndata12' = cx8F8F8F
      'gndata11' = cxF1F1F1
      'gndata10' = cxABABAB
      'gndata9' = cxBDBDBD
      'gndata8' = cxCFCFCF
      'gndata7' = cxD9D9D9
      'gndata6' = cx989898
      'gndata5' = cxE9E9E9
      'gndata4' = cxA1A1A1
      'gndata3' = cxB4B4B4
      'gndata2' = cxC6C6C6
      'gndata1' = cxE2E2E2
      'gndata' = cxE2E2E2
      'gnclink' = cx969696
      'gnlink' = cxC4C4C4
      'gntext' = cx111111
      'gblockheader' = cxd4d4d4
      'gcphasebox' = cx000000
      'gphasebox' = cxBBBBBB
      'gczonec' = cxC9C9C9
      'gzonec' = cxD8D8D8
      'gczoneb' = cxD8D8D8
      'gzoneb' = cxE1E1E1
      'gzonea' = cxEBEBEB
      'gcunder' = cxCCCCCC
      'gunder' = cxCCCCCC
      'gcover' = cxF1F1F1
      'gover' = cxF1F1F1
      'gcfinal' = cx777777
      'gfinal' = cx777777
      'gcinitial' = cx222222
      'ginitial' = cx222222
      'gcother' = cxF1F1F1
      'gother' = cxF1F1F1
      'gcmiss' = cx545454
      'gmiss' = cx000000
      'gablock' = cxE0E0E0
      'gblock' = cxF2F2F2
      'gcclipping' = cx000000
      'gclipping' = cxD2D2D2
      'gcstars' = cx000000
      'gstars' = cxD2D2D2
      'gcruntest' = cxA3A3A3
      'gruntest' = cxDDDDDD
      'gccontrollim' = cxC2C2C2
      'gcontrollim' = cxF0F0F0
      'gcerror' = cx000000
      'gerror' = cxA0A0A0
      'gcpredictlim' = cx000000
      'gpredictlim' = cxC8C8C8
      'gcpredict' = cx000000
      'gpredict' = cx000000
      'gcconfidence2' = cx000000
      'gcconfidence' = cx000000
      'gconfidence2' = cxA8A8A8
      'gconfidence' = cxC8C8C8
      'gcfit2' = cx000000
      'gcfit' = cx000000
      'gfit2' = cx000000
      'gfit' = cx000000
      'gcoutlier' = cx000000
      'goutlier' = cxA0A0A0
      'gcdata' = cx000000
      'gdata' = cxD2D2D2
      'ginsetheader' = colors('docbg')
      'ginset' = cxFFFFFF
      'greferencelines' = cx808080
      'gheader' = colors('docbg')
      'gramp3cend' = cx5F5F5F
      'gramp3cneutral' = cxA7A7A7
      'gramp3cstart' = cxF0F0F0
      'gramp2cend' = cx5F5F5F
      'gramp2cstart' = cxF0F0F0
      'gconramp3cend' = cx000000
      'gconramp3cneutral' = cx777777
      'gconramp3cstart' = cxC4C4C4
      'gconramp2cend' = cx5F5F5F
      'gconramp2cstart' = cxF0F0F0
      'gtext' = cx000000
      'glabel' = cx000000
      'gborderlines' = cx000000
      'goutlines' = cx000000
      'gmgrid' = cxF2F2F2
      'ggrid' = cxECECEC
      'gaxis' = cx000000
      'gshadow' = cx000000
      'glegend' = cxFFFFFF
      'gfloor' = cxCCCCCC
      'gwalls' = cxFFFFFF
      'gckran5' = cx000000
      'gkran5' = cxe1e1e1
      'gckran4' = cx000000
      'gkran4' = cxbfbfbf
      'gckran3' = cx000000
      'gkran3' = cx828282
      'gckran2' = cx000000
      'gkran2' = cx454545
      'gckran1' = cx000000
      'gkran1' = cx080808
      'gcdata12' = cx000000
      'gcdata11' = cx000000
      'gcdata10' = cx000000
      'gcdata9' = cx000000
      'gcdata8' = cx000000
      'gcdata7' = cx000000
      'gcdata6' = cx000000
      'gcdata5' = cx000000
      'gcdata4' = cx000000
      'gcdata3' = cx000000
      'gcdata2' = cx000000
      'gcdata1' = cx000000
      'gdata11' = CXe1e1e1
      'gdata5' = CXcfcfcf
      'gdata1' = CXbfbfbf
      'gdata7' = CXababab
      'gdata8' = CX969696
      'gdata2' = CX828282
      'gdata9' = CX6e6e6e
      'gdata3' = CX595959
      'gdata10' = CX454545
      'gdata4' = CX303030
      'gdata6' = CX1c1c1c
      'gdata12' = CX080808;