SAS Stored Processes
Embedding GraphicsWeb pages frequently contain embedded graphic images. For static images, an <IMG> tag is enough to embed the image: <IMG SRC="mykids.gif"> Dynamically generated images, such as charts that vary over time or due to input parameters, are more complicated. Stored processes can generate graphics in addition to HTML output. The following stored process creates a bar chart followed by a tabular report: /* Sales by Region and Product */ *ProcessBody; %stpbegin; title "Sales by Region and Product"; legend1 label=none frame; proc gchart data=sashelp.shoes; hbar3d region / sumvar=sales sum space=.6 subgroup=product shape=cylinder patternid=subgroup legend=legend1; label product='Shoe Style'; run; proc report data=sashelp.shoes; column region product sales; define region / group; define product / group; define sales / analysis sum; break after region / ol summarize suppress skip; run; %stpend; Depending on input parameters, this stored process might produce the following: Note that no special code was added to handle the image. ODS and the stored process framework takes care of the details of delivering both the HTML and the image to the Web browser. This code will handle different image types, through the _GOPT_DEVICE input parameter supported by the %STPBEGIN macro. The image is delivered to the Web browser in different ways depending on the chosen graphics device. JAVA and ACTIVEX images are generated by embedding an <OBJECT> tag in the generated HTML containing the attributes and parameters necessary to invoke the viewer and display the graphic. There is no <IMG> tag in this case. Other commonly used drivers (GIF, JPEG, PNG, ACTXIMG, and JAVAIMG) do use the <IMG> tag. The following code is an HTML fragment generated by the previous stored process using the GIF image driver: <IMG SRC="/SASStoredProcess/do?_sessionid= 7CF645EB-6E23-4853-8042-BBEA7F866B55 &_program=replay&entry= STPWORK.TCAT0001.GCHART.GIF"> The image URL in the <IMG> tag is actually a reference to the SAS Stored Process Web Application using the special stored process named REPLAY. The REPLAY stored process takes two parameters, _SESSIONID and ENTRY. _SESSIONID is new, unique value each time the original stored process is executed. ENTRY is the name of a temporary SAS catalog entry containing the generated image. Image replay uses a special, lightweight version of the stored process sessions feature to hold image files temporarily until the Web browser retrieves them. You can use the REPLAY stored process to replay entries other than embedded images, such as CSS stylesheets, JavaScript include files, PDF files, and HTML or XML files to be displayed in a pop-up window, frame or <IFRAME>. The special macro variable _TMPCAT contains the name of the temporary catalog used for REPLAY entries and the variable _REPLAY contains the complete URL used to reference the REPLAY stored process (except the actual entry name). The _TMPCAT catalog remains on the server only for a limited time. If the catalog is not accessed within a timeout period (typically 15 minutes), the catalog and its contents are deleted. Direct Graphic OutputIn some cases, you might want to generate image output directly from a stored process with no HTML container. This might be useful if you want to include a dynamically generated graphic in static HTML pages or HTML generated by an unrelated stored process. For example, /* Sales by Product - pie chart stored process * * XPIXELS and YPIXELS input parameters are required */ /* assume we want a new image generated * each time the image is viewed - * disable browser caching of this image */ %let old=%sysfunc(stpsrv_header(Pragma, nocache)); /* need test here in case XPIXELS * or YPIXELS are not defined */ /* set up graph display options */ goptions gsfname=_webout gsfmode=replace dev=png cback=cxE0E0E0 xpixels=&XPIXELS ypixels=&YPIXELS ftext=swiss; pattern1 color=yellow; pattern2 color=cyan; pattern3 color=green; pattern4 color=black; pattern5 color=red; pattern6 color=blue; /* create a simple pie chart */ proc gchart data=sashelp.shoes; pie3d product/sumvar=sales; run; quit; This stored process expects XPIXELS and YPIXELS to be passed as input parameters. A typical IMG tag to invoke this stored process might be <IMG SRC="/SASStoredProcess/do?_program= /WebApps/Utilities/Sales+by+Product&XPIXELS= 400&YPIXELS=300"> which results in Note: There is a defect in some Web browser versions that ignores the NOCACHE and Expires directives in the HTTP header. This defect causes the browser to re-use the previously generated image from its cache even if the HTTP header directed that no caching was to occur. This might happen when embedding an image in an HTML page or when directly entering an image URL in the Web browser. The old image might be updated by manually performing a browser REFRESH or RELOAD, but it is difficult to work around this problem without manual intervention. |