BookmarkSubscribeRSS Feed
mcook
Quartz | Level 8

Given a table such as the following.

data Testing;
input Groups $ Var1 $ Var2 Var3;
datalines;
Group1 ABC 2.22 1.12
Group1 BCD 1.11 2.11
Group1 CDE 2.01 1.13
Group2 XYZ 3.21 1.01
Group2 WXY 4.22 0.01
Group2 VWX 5.05 1.05
Group3 JKL 1.12 2.11
Group3 LKJ 6.66 5.55
;

Capture.PNG

Using ODS Tagsets.RTF and proc report I generate this output:

Capture1.PNG

via this code:

proc sort data=Testing;
by Groups;
run;

data Testing;
set Testing;
by Groups;
if last.Groups = 0 then ID = 1;
if (last.Groups = 1) AND (First.Groups = 1) then ID = 1;
if (last.Groups = 0) AND (First.Groups = 0) then ID = 0;

ODS Tagsets.RTF File = "&FilePath.\&FileName..rtf";

proc report data=Testing spanrows
Style(Report)=[Frame=HSides rules=cols];

Columns 
ID Groups Var1 Var2 Var3;

Define ID / display noprint;
define Groups / group
Style(Column)=[vjust=c just=c];
define Var1 / display;
define Var2 / display;
define Var3 / display;

Compute Var1;
if ID = 1 then call define(_ROW_,'Style','Style=[bordertopwidth=0.1pt bordertopcolor=black]');
endcomp;

run;
ODS Tagsets.RTF Close;

I am generating similar tables for others to insert into a docx document, and i do not know the final dimensions such tables will need to take.  I assumed the tables would be easily manipulated in the RTF file to get them into the correct dimensions (changing column widths, etc.)  but i was mistaken.  

 

If i try to manually click and drag any of the interior column borders, to expand or contract a column, the spanrows aspect collapses.  

Capture2.PNG

 

If i manually click and drag an outer vertical frame,  the spanrows collapses, and the table offsets some of the rows.  

Capture3.PNG

is there  a way to manually adjust the size of the table, and individual columns without collapsing the spanrows?  And what is going on with the offsetting of some of the rows?  

 

Is any of this avoidable?  

1 REPLY 1
Cynthia_sas
SAS Super FREQ

Hi:

  I don't recommend fiddling with the tables in Word, after the RTF file is created. I would suggest trying to find out the final table size and then use that size like this:

ods rtf file='c:\temp\samesize.rtf' startpage=no;

proc report data=sashelp.class(obs=5)
  Style(Report)={frame=hsides rules=cols width=6.5in};
  column name age height;
run;

proc report data=sashelp.class(obs=5)
  Style(Report)={frame=hsides rules=cols width=6.5in};
  column name sex age height weight;
run;

proc report data=sashelp.shoes(obs=5)
  Style(Report)={frame=hsides rules=cols width=6.5in};
  column region subsidiary product sales inventory returns;
run;

ods rtf close;

Assuming you have margins of just 1 inch on the right and left side, then the available space on the page would be 6.5 inches (but notice how I just specify width= for each PROC REPORT step, which "spreads" the table as needed without overcontrolling the width of the individual cells. Of course, you can adjust this but you'll want all of your tables to be the same size, which is something that might be known ahead of time in the documentation or the standards document. I just used startpage=no, so the 3 tables would line up on the same page and you could see that each table is lined up with the one beneath it in width.

  Hope this helps,

Cynthia

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 383 views
  • 0 likes
  • 2 in conversation