12.07.2015 Views

SAS to PDF and JPEG (or viewing outputs in Windows ... - PhUSE Wiki

SAS to PDF and JPEG (or viewing outputs in Windows ... - PhUSE Wiki

SAS to PDF and JPEG (or viewing outputs in Windows ... - PhUSE Wiki

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

LIST ALL OUTPUTS FOUND IN DIRECTORY AND KEEP THE ONES REQUIRED1) Get list of all <strong>outputs</strong> found <strong>in</strong> direc<strong>to</strong>ry specified%let folder = $HOME;<strong>PhUSE</strong> 2006** Get <strong>outputs</strong> <strong>in</strong> direc<strong>to</strong>ry specified **;filename entree pipe "ls &folder/*.*";data server (label="list of <strong>outputs</strong> found");length output $100 ;<strong>in</strong>file entree;<strong>in</strong>put output ;output = reverse( scan( reverse(output), 1, '/') );run ;2) Comb<strong>in</strong>e <strong>outputs</strong> found with <strong>outputs</strong> <strong>in</strong> dataset (ie. <strong>outputs</strong> with titles). Indeed the direc<strong>to</strong>ry may conta<strong>in</strong> other typesof <strong>outputs</strong> so it’s imp<strong>or</strong>tant that only the study <strong>outputs</strong> are kept.** S<strong>or</strong>t Study <strong>outputs</strong> **;proc s<strong>or</strong>t data=sasuser.SAP (keep=type output sap title) out=SAP nodupkey ;by output ;run ;data Study (label="List of <strong>outputs</strong> <strong>to</strong> imp<strong>or</strong>t" drop=sap);attrib fileext length=$5 label="Output extension type"outname length=$20 label="Output name from SAP"outnum length=8 label="Output number from SAP";merge server (<strong>in</strong>=A)SAP (<strong>in</strong>=B);by output ;if A <strong>and</strong> B ;fileext = scan(output, 2, '.') ;outnum = <strong>in</strong>put( substr(sap, 2, length(sap)-1 ), 8.) ;outname = put( substr(sap, 1, 1), $type.) ;run ;3) F<strong>in</strong>d the number of different types of <strong>outputs</strong> <strong>and</strong> create macro variables <strong>to</strong> setup the page size of each one** Get list of different catg<strong>or</strong>ies <strong>and</strong> file types found **;proc s<strong>or</strong>t data=Study (keep=fileext type)out=difftype (label="list of different file types found") nodupkey ;by type fileext ;run ;data _null_;set difftype end=f<strong>in</strong> ;if fileext = "OUT" then do;ls = 93; ps=73; <strong>or</strong>ient="P<strong>or</strong>trait";end;else do;ls = 132; ps=52; <strong>or</strong>ient="L<strong>and</strong>scape";end;call symput('nls' || left(_n_), trim(ls) );call symput('nps' || left(_n_), trim(ps) );call symput('n<strong>or</strong>ient' || left(_n_), trim(<strong>or</strong>ient) );call symput('ntype' || left(_n_), trim(type) );call symput('file' || left(_n_), trim(fileext) );2


<strong>PhUSE</strong> 2006if f<strong>in</strong> then call symput('<strong>to</strong>tfile', left(_n_) );run ;LOOP ON EACH TYPE OF OUTPUT (CATEGORY AND TYPE) AND CREATE A <strong>PDF</strong> FILE%do zz = 1 %<strong>to</strong> &<strong>to</strong>tfile;%put **************************************************;%put ** Loop<strong>in</strong>g on extensions : &&ntype&zz &&file&zz ;%put **************************************************;Graph files%if &&file&zz. =cgm %then %do;Setup ODS environment. This <strong>in</strong>cludes pagesize, l<strong>in</strong>esize <strong>and</strong> <strong>or</strong>ientationtitle;footnote;options <strong>to</strong>pmarg<strong>in</strong>=0.25 leftmarg<strong>in</strong>=0.25 rightmarg<strong>in</strong>=0.25;options ls=&&nls&zz ps=&&nps&zz <strong>or</strong>ientation=&&n<strong>or</strong>ient&zz papersize="ISOA4" ovp;Create macro variables with all the cgm output description (ie. title). This will be used <strong>to</strong> describe the output.proc s<strong>or</strong>t data=Study out=cgmfile (label="List of CGM <strong>outputs</strong>") nodupkey;by outname outnum output ;where <strong>in</strong>dex(output, 'cgm') > 0 <strong>and</strong> <strong>in</strong>dex(type, "&&ntype&zz.") > 0 ;run ;%let <strong>to</strong>tfile=0;data _null_;length fileext $10. ;set cgmfile end=f<strong>in</strong> ;call symput('outp' || left(_n_), trim(left(output)) );call symput('outn' || left(_n_), tranwrd( trim( left(outnum)), '.', '_'));if f<strong>in</strong> then call symput('<strong>to</strong>tfile', left(_n_) );run ;proc greplay igout=w<strong>or</strong>k.gseg nofs;delete _all_ ;run;quit;** Read all cgm <strong>outputs</strong> found **;%do i = 1 %<strong>to</strong> &<strong>to</strong>tfile;filename gsasfile "&folder./&&outp&i." ;goptions reset=global gaccess=gsasfile gsfmode=replacenoprompt device=cgmcrt;goptions reset=all gunit=pct b<strong>or</strong>dercback=white col<strong>or</strong>s=(black blue green red)ftext='courier new' htitle=3 htext=3hsize=4<strong>in</strong> vsize=3.8<strong>in</strong>;Graphic Outputs are s<strong>to</strong>red <strong>in</strong> sasw<strong>or</strong>k catalog,proc gimp<strong>or</strong>t fileref=gsasfilefiletype=cgmf<strong>or</strong>mat=b<strong>in</strong>ary gout=w<strong>or</strong>k.gseg;run;Add title <strong>to</strong> graph description3


<strong>PhUSE</strong> 2006proc catalog cat=w<strong>or</strong>k.gseg entrytype=grseg;change cgm = F_&&outn&i ;modify F_&&outn&i (description="&&outp&i.");run;quit ;%end;Create Graph <strong>PDF</strong> fileods list<strong>in</strong>g close ;ods pdf file=”$HOME/&&ntype&zz.._&&file&zz...pdf” style=Pr<strong>in</strong>terSmaller ;** Create cgm <strong>outputs</strong> <strong>in</strong> <strong>PDF</strong> **;%do I = 1 %<strong>to</strong> &<strong>to</strong>tfile;goptions reset=goptions b<strong>or</strong>der cback=white col<strong>or</strong>s=(black) ;ods proclabel = “Figure &&outn&I” ; Bookmarkproc greplay igout=w<strong>or</strong>k.gseg nofs;replay F_&&outn&i ;run;quit;%end ;ods pdf close;ods list<strong>in</strong>g;%end;ASCII files%else %do;Read every ASCII output <strong>and</strong> s<strong>to</strong>re it <strong>in</strong> 1 dataset. The dataset conta<strong>in</strong>s <strong>in</strong>f<strong>or</strong>mation about the output name,page numbers <strong>and</strong> the <strong>in</strong>f<strong>or</strong>mation read.filename attdir ("&folder./*.&&file&zz.") ;Data o2_data1 (label="ASCII Outputs" keep=output text page nl<strong>in</strong>e) ;reta<strong>in</strong> page 0 <strong>or</strong>ient 93;attrib text length=$400 label='Text Read'myfile length=$200 label='Full Filename'output length=$100 label='File name'temp length=$100 label='File name without extension'page length=8 label='Page number ';<strong>in</strong>file attdir dsd missover lrecl=256 length=l<strong>in</strong>elen filename=myfile;<strong>in</strong>put firstvar $1-10 @ ;D1_vlen=l<strong>in</strong>elen;<strong>in</strong>put @1 text $vary<strong>in</strong>g256. D1_vlen ;output = reverse( scan( reverse(myfile), 1, '/') );temp = trim( scan (output, 1, '.'));if <strong>in</strong>dex(text, trim(temp) || ' ') > 0 then page = page + 1;nl<strong>in</strong>e = _n_ ;run ;proc s<strong>or</strong>t data=o2_data1 ;by output page nl<strong>in</strong>e;run ;Keep only <strong>outputs</strong> found <strong>in</strong> track<strong>in</strong>g. This is <strong>in</strong> case m<strong>or</strong>e <strong>outputs</strong> are found <strong>in</strong> the direc<strong>to</strong>ry which are notpart of the study rep<strong>or</strong>ts, eg, QC <strong>outputs</strong>.data o2_data2 (label="ASCII <strong>outputs</strong> found <strong>in</strong> track<strong>in</strong>g");4


<strong>PhUSE</strong> 2006proc gimp<strong>or</strong>t fileref=gsasfilefiletype=cgmf<strong>or</strong>mat=b<strong>in</strong>arygout=w<strong>or</strong>k.gseg;run;Rename CGM output <strong>in</strong> catalog. Add description <strong>to</strong> graph us<strong>in</strong>g method described <strong>in</strong> previous sectionproc catalog cat=w<strong>or</strong>k.gseg entrytype=grseg;change cgm = F_&&outn&i ;modify F_&&outn&i (description="&&outp&i.");run;quit ;%end;SAVE GRAPHS AS <strong>JPEG</strong> FILESLoop on every output found <strong>in</strong> the sasw<strong>or</strong>k catalog%do i = 1 %<strong>to</strong> &<strong>to</strong>tfile;filename OUTGRAPH "&folder./&&outf&i." ;Options that produce a <strong>JPEG</strong> file with the c<strong>or</strong>rect sett<strong>in</strong>gsgoptionsdevice =jpeggsfname =OUTGRAPHgsflen =80gsfmode =replacehsize =8.4<strong>in</strong>vsize =6.3<strong>in</strong>;proc greplay igout=WORK.GSEG nofs;replay F_&&outn&i ;quit;Filename OutGraph clear;%end ;SEND THE <strong>JPEG</strong> TO WINDOWS ENVIRONMENTDifferent methods can be used <strong>to</strong> send the <strong>JPEG</strong> files, f<strong>or</strong> example us<strong>in</strong>g FTP. Once the files are <strong>in</strong> the W<strong>in</strong>dowsenvironment, you can use the preview option <strong>to</strong> view the files, zoom <strong>in</strong>/zoom out <strong>and</strong> manipulate the files easily.This is particularly useful when you’re want a general view of the graphs <strong>or</strong> if you’re look<strong>in</strong>g f<strong>or</strong> examples of graphs.CONCLUSIONThis paper has shown how <strong>to</strong> convert <strong>outputs</strong> <strong>to</strong> <strong>PDF</strong> <strong>and</strong> group them by type, allow<strong>in</strong>g the client <strong>to</strong> use bookmarks <strong>to</strong>review <strong>outputs</strong> quickly. Us<strong>in</strong>g bookmarks means mem<strong>or</strong>iz<strong>in</strong>g <strong>outputs</strong> name is no longer necessary. The advantage ofus<strong>in</strong>g <strong>PDF</strong> is that the files can be viewed quickly across platf<strong>or</strong>ms.We’ve also seen how <strong>to</strong> convert <strong>outputs</strong> from CGM <strong>to</strong> <strong>JPEG</strong> f<strong>or</strong>mat <strong>and</strong> (pre)view the files on the PC/W<strong>in</strong>dowsplatf<strong>or</strong>m. This can save time when re<strong>view<strong>in</strong>g</strong> <strong>or</strong> QC<strong>in</strong>g many figuresAn advantage of us<strong>in</strong>g PC/w<strong>in</strong>dows is that it’s easy <strong>to</strong> share <strong>outputs</strong>. Regard<strong>in</strong>g this paper, if the <strong>PDF</strong> files <strong>and</strong> <strong>JPEG</strong>files are s<strong>to</strong>red on a netw<strong>or</strong>k drive then they can be reused <strong>in</strong> the future <strong>to</strong> identify <strong>outputs</strong> <strong>and</strong> hence programs,thereby (potentially) reduc<strong>in</strong>g programm<strong>in</strong>g time.7


ACKNOWLEDGMENTS<strong>PhUSE</strong> 2006Internet search eng<strong>in</strong>es f<strong>or</strong> f<strong>in</strong>d<strong>in</strong>g previous papers with code <strong>or</strong> similar issues.CONTACT INFORMATIONYour comments <strong>and</strong> questions are valued <strong>and</strong> encouraged. Contact the auth<strong>or</strong> at:Xavier PasseraDe<strong>to</strong>ur Solutions LtdWelwyn Garden City, UKMobile +44 (0)7930 472 690Email: Xavier.Passera@de<strong>to</strong>ursolutions.co.ukWeb: www.de<strong>to</strong>ursolutions.co.uk<strong>SAS</strong> <strong>and</strong> all other <strong>SAS</strong> Institute Inc. product <strong>or</strong> service names are registered trademarks <strong>or</strong> trademarks of <strong>SAS</strong>Institute Inc. <strong>in</strong> the USA <strong>and</strong> other countries. ® <strong>in</strong>dicates USA registration.Other br<strong>and</strong> <strong>and</strong> product names are trademarks of their respective companies.8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!