title: How to create nice tables using PROC REPORT and ODS RTF output
body: <p>I want to create a 'nice looking table' using the SAS <code>ODS RTF</code> output and the <code>PROC REPORT</code> procedure. After spending the whole day on Google I've managed to produce the following:</p>
  
  <p><strong>The dataset</strong></p>
  
  <pre><code>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; 
  </code></pre>
  
  <p>** The code for creating the rtf-file **</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>This generates an RTF table in Word something like the following (a little simplified):</p>
  
  <p><img src="https://i.stack.imgur.com/uOsom.png" alt="What I get"></p>
  
  <p>However, I want to add a variable lable 'Variable 1, n (%)' above the groups <strong>in the variable name column as a separate row</strong> (NOT in the header row). I also want to add additional variables and statistics in an aggregated table.</p>
  
  <p>In the end, I want something that looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/1KSLB.jpg" alt="enter image description here"></p>
  
  <p>I have tried "everything" - is there anyone who knows how to do this?</p>