Return to Archive

SAS Tip of the Month
December 2006

This month will show a method for generating a figure within a RTF document using ODS RTF. Lets first look at the data:

    Consumption of Red Meat and
    Poultry, Per Capita:
    Year Beef Pork Chck Trky
    1988 72.6 52.5 55.0 15.7
    1989 69.3 52.0 57.0 16.6
    1990 67.8 49.8 60.0 17.6
    1991 66.8 50.4 62.0 17.9
    1992 66.5 53.1 66.0 17.8
    1993 65.1 52.4 68.0 17.6
    1994 67.5 53.0 69.0 17.7
    1995 67.0 52.0 68.0 17.7
    1996 67.2 48.4 69.4 18.2
    1997 65.7 47.9 71.4 17.3
    1998 66.7 51.5 72.1 17.7
    1999 67.5 52.7 76.3 17.6
    2000 67.7 51.2 76.9 17.4
    2001 66.4 50.4 76.9 17.6
    2002 67.6 51.5 80.5 17.7
    2003 64.9 51.9 81.5 17.4
    2004 66.1 51.3 84.3 17.1
    2005 67.1 50.3 87.2 16.6

Telling SAS to start an ODS RTF file the following statements are used:

    *Set Directory/Filename for RTF file;
    %let _dirfn=%str(C:\F2-Turkey.rtf);

    *SAS Options;
    options orientation=landscape
            nodate nonumber nobyline;
    run;

    *ODS setup;
    ods listing close;
    ods escapechar '!';
    ods rtf file="&_dirfn"
            style=custom /*Use a customised style*/
            nogtitle nogfootnote;

    *Set GOPTIONS;
    goptions reset=all
             device=png
             target=png
             ftext="Times New Roman"
             xmax=8.95 in ymax=4.25 in;

Now that the setup has been done lets set the titles for the figure:

    title1 j=l "Doodad Trading (NH)"
           j=r "{Page \field{\*\fldinst PAGE}}{ of \field{\*\fldinst NUMPAGES}}";
             /*Sets up Page x of y on right side of first line*/
    title2 j=l "Primary Commodity Consumption Analysis";
    title4 j=c "Figure 1";
    title5 j=c "Per Capita Consumption of Red Meat and Poultry";
    footnote1 j=l '!R"\brdrt\brdrs\brdrw10 "' "Source: US Department of Agriculture";
             /*Set upper boarder of footnote area and footnote 1 text*/
    footnote2 j=l "&_dirfn" j=r "&sysdate9.T&systime";;
             /*Put directory and file name on left side and creation date/time on right*/

Now it is the actual plot of the data:

    *Year axis setup;
    axis1 order=(1988 to 2005 by 1)
          label=(h=1 'Year') value=(h=1 a=-65 r=0)
          offset=(0.1 in) major=(h=0.01 in width=3)
          minor=none width=2;
    *Weight consumption (lbs);
    axis2 order=(0 to 90 by 5)
          label=(h=1.0 a=90 'Pounds')
          value=(h=1.0) length=3.6 in
          minor=none width=2;
    *Set symbols;
    symbol1 value=dot h=1.0 width=3 line=1
            i=join color=black;
    symbol2 value=dot h=1.0 width=3 line=1
            i=join color=green;
    symbol3 value=dot h=1.0 width=3 line=1
            i=join color=blue;
    symbol4 value=dot h=1.0 width=3 line=1
            i=join color=red;
    *Do plot;
    proc gplot data=meat1;
        plot pounds*year=meat
             /haxis=axis1
              vaxis=axis2
              legend=legend1;
        legend1 POSITION=(BOTTOM
                          RIGHT
                          INSIDE);
    run;
    quit;

The final output looks like the following:

I do hope you find this month's tip useful. Merry Christmas.

________________________________
Updated December 7, 2006