/* * uuencode.sas - * Simple uuencode utility for DATA Step * Richard A. DeVenezia, August 2003 * * Programming exercise only. * For production SAS jobs doing email use * FILENAME fileref EMAIL 'address' ; * and !EM_ATTACH! directive * * Based on * uuencode.c - Simple uuencode utility * Jim Cameron, 1997 * http://www.mta.ca/~amiller/cs2621/uuencode.txt */ %macro encode_byte; if byte = 0 then put '60'x @; else do; byte + 20x; put byte pib1. @; end; %mend; %macro uuencode (filename); %local FILEREF; %let FILEREF = "_%substr (%sysfunc (ranuni(0), 9.7), 3)"; length buffer $45; rc = filename (&FILEREF, %sysfunc(quote(&filename))); if rc = 0 then do; fid = fopen (&FILEREF, 'I', 45, 'B'); if fid > 0 then do; put %sysfunc(quote(begin 600 &filename)); do while (0 = fread (fid)); len = frlen (fid); rc = fget (fid, buffer, len); byte = len; %encode_byte do i = 1 to len by 3; byte1 = peek (addr(buffer)+i-1,1); byte2 = peek (addr(buffer)+i+0,1); byte3 = peek (addr(buffer)+i+1,1); byte = brshift (band (byte1, 0FCx), 2); %encode_byte byte = blshift (band (byte1, 003x), 4) + brshift (band (byte2, 0F0x), 4); %encode_byte byte = blshift (band (byte2, 00Fx), 2) + brshift (band (byte3, 0C0x), 6); %encode_byte byte = band (byte3, 03Fx); %encode_byte end; put; end; rc = fclose (fid); put 'end' ; end; rc = filename (&FILEREF, ''); end; %mend; options mprint; ods listing close; data xy; do x = 1 to 20; y = ranuni (0); output; end; run; filename pngImage 'c:\temp\xy.png'; goptions targetdevice=png device=png gsfname=pngImage hsize=3in vsize=3in htext=4pct ftext=Swiss; goptions i=join; symbol1 v=dot; title "Test plot"; footnote j=r "for email delivery"; proc gplot data=xy; plot y*x; run; quit; options source; data _null_; file 'c:\temp\xy.uue'; put 'Blah'; %uuencode (c:\temp\xy.png) put 'Blah blah'; %uuencode (c:\temp\xy.png) put 'Blah blah blah'; %uuencode (c:\temp\xy.png) put 'Blah blah blah blah'; %uuencode (c:\temp\xy.png) stop; run; options nosource; options noxwait noxsync; x 'c:\opt\winzip\winzip32 c:\temp\xy.uue'; filename pngImage;