Creating and emailing an RTF document under MVS
RTF is a document format which can be easily read by Microsoft Word, and by other applications such as OpenOffice.org on various hardware and software platforms. The program below shows sample JCL needed to create an RTF file containing a graph and a table, along with the resulting RTF file itself.
You could get much fancier, changing the font sizes and colors of various things, creating side-by-side graphics, and so forth, but I wanted to stick with a simple example.
p>I did want to point out the graph type I used, which is relatively new:
This is a radar chart, and it is often used to compare multiple values across multiple groups. In this example with randomly generated data, you can see that Sacramento and Oakland have higher medical costs than surgical costs, but the other locations have higher surgical costs than medical costs. PROC GRADAR is documented in the Online Docs, which contain several other examples.
Two other new graph types that may be of interest: GAREABAR lets you display the magnitude of two variables of interest, and there's a nifty example.
Here's the JCL and source code; you will probably need to change the JCL to match your site's requirements (in particular, you will need to change the JOB card and possibly the name of the catalogued procedure in the EXEC card and the unit name in the ODSTEXT DD statement:
//EMAILRTF JOB xxxxxx,'EMAIL RTF',NOTIFY=&SYSUID,
// MSGCLASS=X,CLASS=S
//*
/*ROUTE PRINT FETCH
//*
//S1REPORT EXEC SASPROD,
// OPTIONS='ls=71 noovp nocenter errorabend errorcheck=strict'
//ODSTEXT DD DSN=&SYSUID..ODSTEMP.RTF,DISP=(MOD,CATLG,CATLG),
// LRECL=16392,RECFM=VB,SPACE=(16392,(1000,2000)),
// UNIT=SYSWRK
//SYSIN DD *,DLM='\\'
options errorcheck=strict noovp nocenter;
data Costs;
length PurchMC ProvMC Type $8.;
format Cost comma10.2;
do i = 1 to 20;
do purchmc = 'Hay', 'Rch', 'Oak', 'Sac', 'SF';
do provmc = 'SF', 'Oak', 'Sac', 'Hay', 'Rch';
Cost = round(ranuni(94612)*100, .01);
if ranuni(95819) > .5 then
type = 'Medical';
else
type = 'Surgical';
output;
end;
end;
end;
run;
/* Empty the output file, in case this is a rerun. */
data _null_;
file odstext old;
run;
/* Send output to RTF */
options orientation=portrait;
ods rtf file=odstext style=sasweb;
ods listing close;
ods rtf startpage=never;
/* Send graphics to PNG (somewhat arbitrary choice). */
goptions
reset = goptions
device = png
target = png
xmax = 5in
ymax = 4in;
title 'Cost by Type by Medical Center';
ods rtf text='Here is a chart:';
proc gradar data=Costs;
chart purchmc
/ sumvar=Cost
overlay=Type
cstars=(red blue)
starcircles=(0.5 1.0)
cstarcircles=black
;
run;
/* Create table output */
ods rtf text='And here is a table:';
proc report data=Costs nofs missing;
column type purchmc Cost n;
define type / Group 'Type';
define purchmc / group 'Medical Center';
define Cost / analysis sum 'Cost';
define n / 'Records';
run;
/* Close ODS destination */
ods rtf close;
/* Empty the output file, in case this is a rerun. */
data _null_;
length filename $44.;
file odstext mod close=free filename=filename;
call symput('REPORTDSN', trim(filename)); ;
run;
/* Send via email */
filename email email
attach=("&REPORTDSN."
name='emailrtf'
lrecl=16392
type='text/rtf'
extension='rtf')
to='Jack.Hamilton@kp.org'
from='Jack.Hamilton@kp.org'
subject='Test File';
/* Send the mail */
data _null_;
file email;
put 'SAS Output is attached.';
run;
//
The results are here.

0 Comments:
Post a Comment
<< Home