BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I have some SAS output that needs to be printed in a tabular form and exported to a Word document. The SAS output has several sections corresponding to a group variable. So far I have;

1. Organize the output into a SAS data set. Use PROC PRINT with BY and ID statements to create a tabular output with separate sections according to the BY groups.

2. Use ods rtf to put the tabular output in a rtf file and proc template to change style settings.

The rtf output looks almost like what I need, except the table needs internal lines to delineate sections created by the “BY” statement in “PROC PRINT”. The options for “rules” in define styles in Proc Template does not seem to extend to this case.

Does anyone have any experience with doing this? Thanks for any tips/advice you can share!

SL
3 REPLIES 3
deleted_user
Not applicable
Unfortunately, the ability to specify a line to delineate between bygroups is not available in Proc Print or in Proc Template.
deleted_user
Not applicable
Thanks. what a bummer. But !!

Is there an alternative procedure that can do it relatively painlessly?
Cynthia_sas
SAS Super FREQ
Hi:
I agree that the capability is not there in PROC PRINT. However if you combine RTF control strings with Proc Template, it is possible to get a line either ABOVE the byline or BELOW the byline.

I used the only RTF control strings that I know for lines: \brdrb (means border bottom) and \brdrs (means border solid) and \brdrt (means border top)

The first style template, in the program below, MYRTF_DIV has a line under the byline. For that template, you also need a line (\line) ABOVE the table, so that the line for the byline does not sit on top of the table.

The second style template, in the program below, MYRTF_ALT has a line above the by line. In this instance, you don't need a blank line on top of the table. And then the third style template just does a line above and a line below.

This may or may not be the look you want. I'm sure that with a little research into RTF control strings, you may be able to come up with a different look.

cynthia
[pre]
options nodate nonumber orientation=portrait center;
ods path work.templ(update)
sashelp.tmplmst(read);

proc template;
define style myrtf_div;
parent=styles.rtf;
style Byline from Byline/
pretext='\brdrb\brdrs';
style Table from Table /
pretext = '\line';
end;

define style myrtf_alt;
parent=styles.rtf;
style Byline from Byline/
pretext='\brdrt\brdrs';
end;

define style myrtf_both;
parent=styles.rtf;
style Byline from Byline/
pretext='\brdrt\brdrs \brdrb\brdrs';
style Table from Table /
pretext = '\line';
end;
run;

ods listing close;
proc sort data=sashelp.class out=class;
by sex;
run;

ods rtf file='c:\temp\div1.rtf' style=myrtf_div;
proc print data=class;
by sex;
var name age height;
run;
ods rtf close;

ods rtf file='c:\temp\div2.rtf' style=myrtf_alt;
proc print data=class;
by sex;
var name age height;
run;
ods rtf close;

ods rtf file='c:\temp\div3.rtf' style=myrtf_both;
proc print data=class;
by sex;
var name age height;
run;
ods rtf close;
[/pre]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 3 replies
  • 737 views
  • 0 likes
  • 2 in conversation