#!/bin/awk -f ############################################################################# # Sets up SASweave output routines for weaving (rather than tangling) # # Copyright (C) 2006 Russell V. Lenth - University of Iowa # Revised: 2007.08.21 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # I changed the last line for SAS 9.2 --KK ############################################################################## ### What to display at beginning of sasfile function fileStart () { print "*** SAS file generated by sasweave ***;\n" > sasfile print "options nocenter nodate nonumber skip=0 ls=120 formdlim=''" >> sasfile print " formchar = '|----|+|---+=|-/\\<>*';" >> sasfile print "title; footnote;\n" >> sasfile print "proc iml; file print;" >> sasfile } ### Function to output a string into sasfile wrapped in a "put" statement ### Long strings are broken up to avoid exceeding SAS's line size function put(stg) { gsub("\"", "\"\"", stg) if (length(stg) <= 110) { # Need special treatment for % and &, else SAS gets mad gsub("%", "%\" \"", stg) ### intercept "%" characters gsub("&", "&\" \"", stg) ### intercept "&" characters print " put \"" stg "\";" >> sasfile } else { ### split into several lines split(stg, words, " ") out = "" for (i = 1; i in words; i++) { if (length(out) + length(words[i]) < 110) { out = out " " words[i] } else { gsub("%", "%\" \"", out) gsub("&", "&\" \"", out) print " put \"" out "\";" >> sasfile out = words[i] } } print " put \"" out "\";" >> sasfile } } ### What to put in sasfile at beginning of a text chunk function beginText() { print "*** Begin text chunk ***;" >> sasfile print "options ls=120;" >> sasfile print "ods listing exclude none;" >> sasfile if (IMLactive) print "file print;" >> sasfile else print "proc iml; file print;" >> sasfile } ### What to put in sasfile at the end of a text chunk function endText() { if (!IMLactive) print "quit;" >> sasfile print "*** End text chunk ***;\n" >> sasfile print "options ls=" ls ";" >> sasfile ### I'm worried about losing text chunks here too; but tests seem to work... if (hide) print "ods listing exclude all;" >> sasfile print "\n*** Code chunk", chunklab " ***;" >> sasfile } ### What to put into sasfile to set up a graph function setupGraph() { pfn = figdir "/" prefixStg "-" chunklab ".pdf" upfn = infigdir "/" prefixStg "-" chunklab print "filename grafout", "\"" pfn "\";" >> sasfile print "goptions device=pdfc gsfname=grafout gsfmode=replace;" >> sasfile print "goptions hsize =", hsize, "in vsize =", vsize, "in;" >> sasfile if (hide) ### ODS stmt for hiding output will suppress the graph too -- so select it print "ods listing select gplot;" >> sasfile viewpt = "10 10 " int(35+72*hsize) " " int(35+72*vsize-30*striptitle) # Old... for sas 9.1; in sas 9.2, these values chop out part of the image... viewpt = "37 37 " int(35+72*hsize) " " int(35+72*vsize-30*striptitle) } ### What to put into sasfile to set up graph resulting from an 'sg' procedure. These don't obey goptions, apparently, so need this function setupsgGraph() { pfn = figdir "/" prefixStg "-" chunklab ".pdf" upfn = infigdir "/" prefixStg "-" chunklab print "ods pdf file=", "\"" pfn "\";" >> sasfile print "ods graphics / noborder height =", hsize, "in width =", vsize, "in;" >> sasfile if (hide) ### ODS stmt for hiding output will suppress the graph too -- so select it print "ods select gplot;" >> sasfile viewpt = "10 " int(750-72*vsize-12*odsstriptitle) " " int(35+72*hsize) " " int(772-12*odsstriptitle) }