Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7797687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:45:51+00:00 2026-06-01T23:45:51+00:00

I want to create a ‘nice looking table’ using the SAS ODS RTF output

  • 0

I want to create a ‘nice looking table’ using the SAS ODS RTF output and the PROC REPORT procedure. After spending the whole day on Google I’ve managed to produce the following:

The dataset

DATA survey;
   INPUT id var1 var2 var3 var4 var5 var6 ;
   DATALINES;
 1  1  35 17  7 2 2
17  1  50 14  5 5 3
33  1  45  6  7 2 7
49  1  24 14  7 5 7
65  2  52  9  4 7 7
81  2  44 11  7 7 7
2   2  34 17  6 5 3
18  2  40 14  7 5 2
34  2  47  6  6 5 6
50  2  35 17  5 7 5
;
RUN;

DATA survey;
    SET survey;
    LABEL var1 ='Variable 1';
    LABEL var2 ='Fancy variable 2';
    LABEL var3 ='Another variable no 3';
RUN;

LIBNAME mylib 'C:\my_libs';
RUN;

PROC FORMAT LIBRARY = mylib.survey;
    VALUE groups 1 = 'Group A'
                2 = 'Group B'
    ;

OPTIONS FMTSEARCH = (mylib.survey);

DATA survey;
    SET survey;
    FORMAT var1 groups.;
RUN; 

** The code for creating the rtf-file **

ods listing close;
ods escapechar = '^';
ods noproctitle;

options nodate number;
footnote;

ODS RTF FILE = 'C:\my_workdir\output.rtf' 
author = 'NN'
title = 'Table 1 name'
bodytitle 
startpage = no
style = journal;
options papersize = A4 
orientation = landscape;

title1 /*bold*/ /*italic*/ font = 'Times New Roman'  height = 12pt justify = center underlin = 0 color = black bcolor = white 'Table 1 name';
footnote1 /*bold*/ /*italic*/ font = 'Times New Roman'  height = 9pt justify = center underlin = 0 color = black bcolor = white 'Note: Created on January 2012';

PROC REPORT DATA = survey nowindows headline headskip MISSING
    style(header) = {/*font_weight = bold*/ font_face = 'Times New Roman' font_size = 12pt just = left}
    style(column) = {font_face = 'Times New Roman' font_size = 12pt just = left /*asis = on*/};
    COLUMN var1 var1=var1_n var1=var1_pctn;
    DEFINE var1 / GROUP ORDER=FREQ DESCENDING 'Variable';
    DEFINE var1_n / ANALYSIS N 'Data/(N=)';
    DEFINE var1_pctn / ANALYSIS PCTN format = percent8. '';
RUN;

ODS RTF CLOSE;

This generates an RTF table in Word something like the following (a little simplified):

What I get

However, I want to add a variable lable ‘Variable 1, n (%)’ above the groups in the variable name column as a separate row (NOT in the header row). I also want to add additional variables and statistics in an aggregated table.

In the end, I want something that looks like this:

enter image description here

I have tried “everything” – is there anyone who knows how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:45:54+00:00Added an answer on June 1, 2026 at 11:45 pm

    I know this has been open for awhile, but I too was struggling with this for awhile, and this is what I figured out. So…

    In short, SAS has trouble outputting nicely formatted tables that contain more than one type of table “format” in them. For instance, a table where the columns change midway through (like you commonly find in the “Table 1” of a research study describing the study population).

    In this case, you’re trying to use PROC REPORT, but I don’t think it’s going to work here. What you want to do is stack two different reports on top of each other, really. You’re changing the column value midway through and SAS doesn’t natively support that.

    Some alternative approaches are:

    • Perform all your calculations and carefully output them to a data set in SAS, in the positions you want. Then, use PROC PRINT to print them. This is what I can only describe as a tremendous effort.

    • Create a new TAGSET that allows you to output multiple files, but removes the spacing between each one and aligns them to the same width, effectively creating a single table. This is also quite time consuming; I attempted it using HTML with a custom CSS file and tagset, and it wasn’t terribly easy.

    • Use a different procedure (in this case, PROC TABULATE) and then manually delete the spacing between each table and fiddle with the width to get a final table. This isn’t fully automated, but it’s probably the quickest option.

    PROC TABULATE is cool because you can use multiple table statements in a single example. Below, I put some code in that shows what I’m talking about.

    DATA survey;
       INPUT id grp var1 var2 var3 var4 var5;
       DATALINES;
         1  1  35 17  7 2 2
        17  1  50 14  5 5 3
        33  1  45  6  7 2 7
        49  1  24 14  7 5 7
        65  2  52  9  4 7 7
        81  2  44 11  7 7 7
        2   2  34 17  6 5 3
        18  2  40 14  7 5 2
        34  2  47  6  6 5 6
        50  2  35 17  5 7 5
    ;
    RUN;
    

    I found your example code to be a little confusing; var1 looked like a grouping variable, and var2 looked like the first actual analysis variable, so I slightly changed the code. Next, I quickly created the same format you were using before.

    PROC FORMAT;
        VALUE groupft 1 = 'Group A' 2 = 'Group B';
    RUN;
    
    DATA survey;
        SET survey;
        LABEL var1 ='Variable 1';
        LABEL var2 ='Fancy variable 2';
        LABEL var3 ='Another variable no 3';
        FORMAT var1 groupft.;
    RUN;
    

    Now, the meat of the PROC TABULATE statement.

    PROC TABULATE DATA=survey;
        CLASS grp;
        VAR var1--var5;
        TABLE MEDIAN QRANGE,var1;
        TABLE grp,var2*(N PCTN);
    RUN;
    

    TABULATE basically works with commas and asterisks to separate things. The default for something like grp*var1 is an output where the column is the first variable and then there are subcolumns for each subgroup. To add rows, you use a column; to specify which statistics you want, you add a keyword.

    This above code gets you something close to what you had in your first example (not ODS formatted, but I figure you can add that back in); it’s just in two different tables.

    I found the following papers useful when I was tackling this problem:

    http://www.lexjansen.com/pharmasug/2005/applicationsdevelopment/ad16.pdf

    http://www2.sas.com/proceedings/sugi31/089-31.pdf

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a stored procedure (on SQL Server 2005) that fetches a
I want create a pdf using iText. The method which does this is a
say, I have a table TABLE(col1,col2,col3) and, I want create a index INDEX(col1=table.col1+table.col2)
I want create own SetupTypeDlg using wix default dialogs to show the disk costs
I want create a site by command line using appcmd. How can I associate
I want create a excel with Apache POI in java and I must insert
i want create image animation , i have 50 images with png format now
I want create module which update list of usb devices automatically (not only mass
We want to create a widget platform for a particular website. I couldn't find
I want to create a file in the current directory (where the executable is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.