Zipping and Emailing a file under MVS
This example is completely platform-dependent, and runs under MVS and its descendents. Windows and Unix platforms can perform a similar function using pipes.
Release 9.2 of SAS will probably support the SASZIPAM engine for reading zip files, under most platforms (including MVS, where it currently doesn't work). It doesn't sound likely that a write engine will be added, and it is almost certain that support for enhanced encryption, in either direction, will not be added.
The attached SAS job shows how to write an Excel workbook and and PDF using ODS, place those files into a ZIP archive under MVS, and then email the results.
The job attempts to do as much as possible using DDnames rather than using data set names; I wanted to take advantage of JCL for naming and enqueuing. The job could undoubtedly be made shorter or simpler, but I didn't want to spend a lot of time on it. Documentation for PKZIP for zSeries can be found at www.pkzip.com. If you have the appropriate license, you can encrypt as well as compress files.
Similar code could be written to unZIP files.
If you run the job, please remember to change the email addresses near the bottom from mine to yours; also, you'll have to change the JOB card.
//ZIPSTEP JOB xxxxxx,jobtext,NOTIFY=&SYSUID,CLASS=S,MSGCLASS=X
/*ROUTE PRINT FETCH
/*JOBPARM L=999
//*
//ZIPFILE SET ZIPFILE=&SYSUID..ZIPSTEP.SAMPLE.ZIP
//XLSFILE SET XLSFILE=&SYSUID..ZIPSTEP.TRANSFER.XLS
//PDFFILE SET PDFFILE=&SYSUID..ZIPSTEP.TRANSFER.PDF
//*
//S1DELETE EXEC PGM=IEFBR14
//ZIPFILE DD DSN=&ZIPFILE.,
// DISP=(MOD,DELETE,DELETE),UNIT=SYSWRK,SPACE=(1,1)
//XLSFILE DD DSN=&XLSFILE,
// DISP=(MOD,DELETE,DELETE),UNIT=SYSWRK,SPACE=(1,1)
//PDFFILE DD DSN=&PDFFILE,
// DISP=(MOD,DELETE,DELETE),UNIT=SYSWRK,SPACE=(1,1)
//*
//S2DATA EXEC SASPROD,
// OPTIONS='ls=71 noovp nocenter'
//XLSFILE DD DSN=&XLSFILE,DISP=(NEW,PASS,DELETE),
// UNIT=SYSWRK,SPACE=(TRK,(20,50)),
// RECFM=VB,LRECL=16392
//PDFFILE DD DSN=&PDFFILE,DISP=(NEW,PASS,DELETE),
// UNIT=SYSWRK,SPACE=(TRK,(20,50)),
// RECFM=VB,LRECL=16392
//SYSIN DD *,DLM='\\'
/* Get latest copy of ExcelXP tagset from SAS web site */
filename tagset http
'http://support.sas.com:80/rnd/base/topics/odsmarkup/excltags.tpl';
%include tagset / nosource2;
/* Use it */
ods tagsets.excelxp file=xlsfile record_separator=none style=sasweb;
/* We also want PDF. */
ods pdf file=pdffile notoc style=sasweb;
ods listing close;
title 'Transfers';
/* Sample data */
data test;
length purchmc provmc type $8.;
do purchmc = 'Hay', 'Rch', 'Oak';
do provmc = 'Oak', 'Hay', 'Rch';
do type = 'Volume', 'Expense';
cost = round(ranuni(94612)*100, .01);
output;
end;
end;
end;
run;
/* Set sheet options */
ods tagsets.excelxp
options(sheet_name='Transfers'
frozen_headers='1'
row_repeat='1'
);
proc report data=test missing nofs nocenter
completerows completecols;
column purchmc type provmc, cost cost=totcost;
define purchmc / group 'Purch MC' width=8
order=data;
define type / group 'Type' width=8;
define provmc / across 'Prov MC' width=8
order=data;
define cost / sum 'Cost' format=comma8.2;
define totcost / sum 'Total Cost' width=10 format=comma10.2;
compute provmc;
if type = 'expense' then
call define(_col_, 'style', 'style={background=yellow}');
endcomp;
run;
ods _all_ close;
ods listing;
\//*
//S3ZIP EXEC PGM=PKZIP
//STEPLIB DD DSN=SYSL.PKZIPMVS.NPRD.LOADLIB,DISP=SHR
//XLSFILE DD DSN=&XLSFILE,DISP=(SHR,PASS)
//PDFFILE DD DSN=&PDFFILE,DISP=(SHR,PASS)
//ZIPFILE DD DSN=&ZIPFILE.,DISP=(NEW,CATLG,CATLG),
// UNIT=SYSWRK,SPACE=(TRK,(20,50)),FREE=CLOSE
//SYSIN DD *
-TRANSLATE_TABLE_DATA(EBC#850)
-DATA_DELIMITER(CRLF)
-FILE_TERMINATOR()
-ARCHIVE_OUTFILE(ZIPFILE)
-COMPRESSION_LEVEL(MAXIMUM)
-ZIPPED_DSN(*.*.*.*,++*.*)
-INFILE(XLSFILE)
-ACTION(ADD)
-INFILE(PDFFILE)
-ACTION(ADD)
//*
//S4MAIL EXEC SASPROD,
// OPTIONS='ls=71 noovp nocenter'
//SYSIN DD *,DLM='\\'
filename email email
attach=(".zipstep.sample.zip"
name='Sample' extension='zip')
to='Jack.Hamilton@kp.org'
from='Jack.Hamilton@kp.org'
subject='Sample ZIP file';
data _null_;
file email;
put 'ZIP Sample attached.';
run;
\
The file sample.zip contains the results of running this job.

0 Comments:
Post a Comment
<< Home