SAS Institute. The Power to Know

FOCUS AREAS

Return to previous page

Base SAS

Sample Code

This section contains pieces of sample code that are used in the course of this document.

GLMEX Sample Library Program

   /****************************************************************/
   /*          S A S   S A M P L E   L I B R A R Y                 */
   /*                                                              */
   /*    NAME: GLMEX                                               */
   /*   TITLE: Documentation Examples from PROC GLM                */
   /* PRODUCT: STAT                                                */
   /*  SYSTEM: ALL                                                 */
   /*    KEYS: analysis of variance,                               */
   /*   PROCS: GLM                                                 */
   /*    DATA:                                                     */
   /*                                                              */
   /* SUPPORT: NMM          UPDATE:                                */
   /*     REF:                                                     */
   /*    MISC:                                                     */
   /*                                                              */
   /****************************************************************/
   
   /* Example 1 */
   *---------------snapdragon experiment---------------*
   | as reported by stenstrom, 1940, an experiment was |
   | undertaken to investigate how snapdragons grew in |
   | various soils. each soil type was used in three   |
   | blocks.                                           |
   *---------------------------------------------------*;
   
   data plants;
      input type $ @;
      do block=1 to 3;
         input stemleng @;
         output;
         end;
      cards;
   clarion  32.7 32.3 31.5
   clinton  32.1 29.7 29.1
   knox     35.7 35.9 33.1
   o'neill  36.0 34.2 31.2
   compost  31.8 28.0 29.2
   wabash   38.2 37.8 31.9
   webster  32.5 31.1 29.7
   ;
   
   data mileage;
      input mph mpg @@;
      cards;
   20 15.4 30 20.2 40 25.7 50 26.2 50 26.6 50 27.4 55  . 60 24.8
   ;
   
   /* Choose XML destination in ODS */
   ods xml file="glmex.xml";
   
   proc glm data=plants;
      class type block;
      model stemleng=type block;   run;
   
   proc glm order=data data=plants;
      class type block;
      model stemleng=type block / solution;
      means type / waller regwq;
   
   *-type-order------------clrn-cltn-knox-onel-cpst-wbsh-wstr;
      contrast 'compost vs others'  type -1 -1 -1 -1  6 -1 -1;
      contrast 'river soils vs.non' type -1 -1 -1 -1  0  5 -1,
                                    type -1  4 -1 -1  0  0 -1;
      contrast 'glacial vs drift'   type -1  0  1  1  0  0 -1;
      contrast 'clarion vs webster' type -1  0  0  0  0  0  1;
      contrast 'knox vs oneill'     type  0  0  1 -1  0  0  0;   run;
   
   quit;
     
   /* Close ODS destination */
   ods xml close;

xt UNIX Shell Script

   #!/bin/sh
   
   # Path to Java executable
   JAVA=/bin/java
    
   # Path to XT and XP directories
   XT_DIR=/usr/local/lib/xt
   XP_DIR=/usr/local/lib/xp
      
   # Set Java classpath
   CLASSPATH=$XT_DIR/xt.jar:$XT_DIR/sax.jar:$XP_DIR/xp.jar:$CLASSPATH
     
   # Run XT
   $JAVA -classpath $CLASSPATH \
         -Dcom.jclark.xsl.sax.parser=com.jclark.xml.sax.Driver \
         com.jclark.xsl.sax.Driver \
         $*

GLMEX Version 8 Sample XSL File

      <xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      
      <!-- Declare HTML as output method                            -->
      <!-- This translates things like <br/> in XML to <br> in HTML -->
      <xsl:output method="html"/>
      
      <!-- Process the document root element -->
      <xsl:template match="sasxml">
        <html>
          <head>
            <title><xsl:value-of select="proc/title"/></title>
          </head>
          <body>
            <xsl:apply-templates/>
          </body>
        </html>
      </xsl:template>
      
      <!-- Labels -->
      <xsl:template match="label">
        <a name="{@id}"></a>
      </xsl:template>
      
      <!-- Output objects in general can be tables, batch output, Java applets, -->
      <!-- or ActiveX controls.  Since there is no good way to deal with        -->
      <!-- binary information here, we'll just process tables and batch output. --> 
      <!--                                                                      -->
      <!-- Process output-objects that are tables                               -->
      <xsl:template match="output-object[@type=string('table')]">
        <div align="CENTER">
        <table border="1" cellpadding="5" cellspacing="1" frame="all" rules="groups">
          <xsl:apply-templates select="style"/>
          <xsl:apply-templates select="colspec"/>
          <xsl:apply-templates select="output-head|output-body|output-foot|row"/>
        </table>
        </div>
        <br/>
      </xsl:template>
      <!-- Process output-objects that are batch output                         -->
      <xsl:template match="output-object[@type=string('batch')]">
        <div align="CENTER">
        <pre>
          <xsl:apply-templates/>
        </pre>
        </div>
        <br/>
      </xsl:template>
      
      <!-- Output column headers -->
      <xsl:template match="output-head">
        <thead>
          <xsl:apply-templates select="row"/>
        </thead>
      </xsl:template>
      
      <!-- Output body -->
      <xsl:template match="output-body">
        <tbody>
          <xsl:apply-templates select="row"/>
        </tbody>
      </xsl:template>
      
      <!-- Output column footers -->
      <xsl:template match="output-foot">
        <tfoot>
          <xsl:apply-templates select="row"/>
        </tfoot>
      </xsl:template>
      
      <!-- Column specifiers -->
      <xsl:template match="colspec">
        <xsl:apply-templates select="col"/>
      </xsl:template>
      <xsl:template match="col">
        <colgroup><col/></colgroup>
      </xsl:template>
      
      <!-- Table rows -->
      <xsl:template match="row">
        <tr>
          <xsl:apply-templates select="style"/>
          <xsl:apply-templates select="data"/>
        </tr>
      </xsl:template>
      
      <!-- Table cells -->
      <xsl:template match="data">
        <td>
          <xsl:apply-templates select="style"/>
          <xsl:apply-templates/>
        </td>
      </xsl:template>
      
      <!-- System titles -->
      <xsl:template match="title">
        <h1>
        <xsl:apply-templates select="style"/>
        <xsl:apply-templates/>
        </h1>
      </xsl:template>
      
      <!-- Procedure titles -->
      <xsl:template match="proc-title">
        <h2>
        <xsl:apply-templates select="style"/>
        <xsl:apply-templates/>
        </h2>
      </xsl:template>
      
      <!-- Messages -->
      <xsl:template match="message">
        <p>
        <center>
        <table width="90%" cellpadding="5" cellspacing="1">
          <tr>
            <th valign="top"><xsl:value-of select="@type"/>:</th>
            <td><xsl:apply-templates/></td>
          </tr>
        </table>
        </center>
        </p>
      </xsl:template>
      
      <!-- These nodes should be ignored -->
      <xsl:template match="styles|page">
      </xsl:template>
      
      <!-- These nodes should simply process any nested tags -->
      <xsl:template match="node|leaf|output|proc">
        <xsl:apply-templates/>
      </xsl:template>
      
      <!-- Line breaks -->
      <xsl:template match="br">
        <br/>
      </xsl:template>
      
      <!-- Process style blocks -->
      <xsl:template match="style">
        <!-- Start a style attribute on the current node -->
        <xsl:attribute name="style">
      
        <!-- Add colors -->
        <xsl:for-each select="color">
          <xsl:if test="@background">background:<xsl:value-of select="@background"/>;</xsl:if>
          <xsl:if test="@foreground">color:<xsl:value-of select="@foreground"/>;</xsl:if>
        </xsl:for-each>
      
        <!-- Add font attributes -->
        <xsl:for-each select="font">
          <xsl:if test="@weight">font-weight:<xsl:value-of select="@weight"/>;</xsl:if>
          <xsl:if test="@family">font-family:<xsl:value-of select="@family"/>';</xsl:if>
          <xsl:if test="@italic">font-style:italic;</xsl:if>
        </xsl:for-each>
      
        <!-- Add alignment characteristics -->
        <xsl:for-each select="align">
          <xsl:if test="@horiz">text-align:<xsl:value-of select="@horiz"/>;</xsl:if>
        </xsl:for-each>
      
        <!-- Process border attributes -->
        <xsl:for-each select="border">
          <xsl:if test="@type">border-style:<xsl:value-of select="@type"/>;</xsl:if>
          <xsl:if test="@color">border-color:<xsl:value-of select="@color"/>;</xsl:if>      
          <xsl:if test="@thickness">border-width:<xsl:value-of select="@thickness"/>;</xsl:if>      
        </xsl:for-each>
        </xsl:attribute>
        
        <!-- Process column and row spanning for table cells -->
        <xsl:for-each select="span">
          <xsl:if test="@col">
            <xsl:attribute name="colspan"><xsl:value-of select="@col"/></xsl:attribute>
          </xsl:if>
          <xsl:if test="@row">
            <xsl:attribute name="rowspan"><xsl:value-of select="@row"/></xsl:attribute>
          </xsl:if>
        </xsl:for-each>
      </xsl:template>
      
      </xsl:stylesheet>

GLMEX Version 8 TS1 Sample XSL File

      <xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      
      <!-- Declare HTML as output method                            -->
      <!-- This translates things like <br/> in XML to <br> in HTML -->
      <xsl:output method="html"/>
      
      <!-- Process the document root element -->
      <xsl:template match="odsxml">
        <html>
          <head>
            <title><xsl:value-of select="proc/title"/></title>
          </head>
          <body>
            <xsl:apply-templates/>
          </body>
        </html>
      </xsl:template>
      
      <!-- Labels -->
      <xsl:template match="label">
        <a name="{@name}"></a>
      </xsl:template>
      
      <!-- Output objects in general can be tables, batch output, Java applets, -->
      <!-- or ActiveX controls.  Since there is no good way to deal with        -->
      <!-- binary information here, we'll just process tables and batch output. --> 
      <!--                                                                      -->
      <!-- Process output-objects that are tables                               -->
      <xsl:template match="output-object[@type=string('table')]">
        <div align="CENTER">
        <table border="1" cellpadding="5" cellspacing="1" frame="all" rules="groups">
          <xsl:apply-templates select="style"/>
          <xsl:apply-templates select="colspecs"/>
          <xsl:apply-templates select="output-head|output-body|output-foot|row"/>
        </table>
        </div>
        <br/>
      </xsl:template>
      <!-- Process output-objects that are batch output                         -->
      <xsl:template match="output-object[@type=string('batch')]">
        <div align="CENTER">
        <pre>
          <xsl:apply-templates/>
        </pre>
        </div>
        <br/>
      </xsl:template>
      
      <!-- Output column headers -->
      <xsl:template match="output-head">
        <thead>
          <xsl:apply-templates select="row"/>
        </thead>
      </xsl:template>
      
      <!-- Output body -->
      <xsl:template match="output-body">
        <tbody>
          <xsl:apply-templates select="row"/>
        </tbody>
      </xsl:template>
      
      <!-- Output column footers -->
      <xsl:template match="output-foot">
        <tfoot>
          <xsl:apply-templates select="row"/>
        </tfoot>
      </xsl:template>
      
      <!-- Column specifiers -->
      <xsl:template match="colspecs">
        <xsl:apply-templates select="colspec|colgroup"/>
      </xsl:template>
      <xsl:template match="colgroup">
        <colgroup><xsl:apply-templates select="colspec"/></colgroup>
      </xsl:template>
      <xsl:template match="colspec">
        <col/>
      </xsl:template>
      
      <!-- Table rows -->
      <xsl:template match="row">
        <tr>
          <xsl:apply-templates select="style"/>
          <xsl:apply-templates select="data|header"/>
        </tr>
      </xsl:template>
      
      <!-- Table data cells -->
      <xsl:template match="data">
        <td>
          <xsl:apply-templates select="style"/>
          <xsl:apply-templates/>
        </td>
      </xsl:template>
      
      <!-- Table header cells -->
      <xsl:template match="header">
        <th>
          <xsl:apply-templates select="style"/>
          <xsl:apply-templates/>
        </th>
      </xsl:template>
      
      <!-- System titles -->
      <xsl:template match="title">
        <h1>
        <xsl:apply-templates select="style"/>
        <xsl:apply-templates/>
        </h1>
      </xsl:template>
      
      <!-- Procedure titles -->
      <xsl:template match="proc-title">
        <h2>
        <xsl:apply-templates select="style"/>
        <xsl:apply-templates/>
        </h2>
      </xsl:template>
      
      <!-- Notes -->
      <xsl:template match="note">
        <p>
        <center>
        <table width="90%" cellpadding="5" cellspacing="1">
          <tr>
            <th valign="top">Note:</th>
            <td><xsl:apply-templates/></td>
          </tr>
        </table>
        </center>
        </p>
      </xsl:template>
      
      <!-- Warning -->
      <xsl:template match="warning">
        <p>
        <center>
        <table width="90%" cellpadding="5" cellspacing="1">
          <tr>
            <th valign="top">Warning:</th>
            <td><xsl:apply-templates/></td>
          </tr>
        </table>
        </center>
        </p>
      </xsl:template>
      
      <!-- Errors -->
      <xsl:template match="message">
        <p>
        <center>
        <table width="90%" cellpadding="5" cellspacing="1">
          <tr>
            <th valign="top">Error:</th>
            <td><xsl:apply-templates/></td>
          </tr>
        </table>
        </center>
        </p>
      </xsl:template>
      
      <!-- Fatal Errors -->
      <xsl:template match="fatal-error">
        <p>
        <center>
        <table width="90%" cellpadding="5" cellspacing="1">
          <tr>
            <th valign="top">Fatal<br/>Error:</th>
            <td><xsl:apply-templates/></td>
          </tr>
        </table>
        </center>
        </p>
      </xsl:template>
      
      <!-- These nodes should be ignored -->
      <xsl:template match="styles|page">
      </xsl:template>
      
      <!-- These nodes should simply process any nested tags -->
      <xsl:template match="node|leaf|output|proc">
        <xsl:apply-templates/>
      </xsl:template>
      
      <!-- Line breaks -->
      <xsl:template match="br">
        <br/>
      </xsl:template>
      
      <!-- Process style blocks -->
      <xsl:template match="style">
        <!-- Start a style attribute on the current node -->
        <xsl:attribute name="style">
      
        <!-- Add colors -->
        <xsl:for-each select="color">
          <xsl:if test="@background">background:<xsl:value-of select="@background"/>;</xsl:if>
          <xsl:if test="@foreground">color:<xsl:value-of select="@foreground"/>;</xsl:if>
        </xsl:for-each>
      
        <!-- Add font attributes -->
        <xsl:for-each select="font">
          <xsl:if test="@weight">font-weight:<xsl:value-of select="@weight"/>;</xsl:if>
          <xsl:if test="@family">font-family:<xsl:value-of select="@family"/>';</xsl:if>
          <xsl:if test="@italic">font-style:italic;</xsl:if>
        </xsl:for-each>
      
        <!-- Add alignment characteristics -->
        <xsl:for-each select="align">
          <xsl:if test="@horiz">text-align:<xsl:value-of select="@horiz"/>;</xsl:if>
        </xsl:for-each>
      
        <!-- Process border attributes -->
        <xsl:for-each select="border">
          <xsl:if test="@type">border-style:<xsl:value-of select="@type"/>;</xsl:if>
          <xsl:if test="@color">border-color:<xsl:value-of select="@color"/>;</xsl:if>      
          <xsl:if test="@thickness">border-width:<xsl:value-of select="@thickness"/>;</xsl:if>      
        </xsl:for-each>
        </xsl:attribute>
        
        <!-- Process column and row spanning for table cells -->
        <xsl:for-each select="span">
          <xsl:if test="@columns">
            <xsl:attribute name="colspan"><xsl:value-of select="@columns"/></xsl:attribute>
          </xsl:if>
          <xsl:if test="@rows">
            <xsl:attribute name="rowspan"><xsl:value-of select="@rows"/></xsl:attribute>
          </xsl:if>
        </xsl:for-each>
      </xsl:template>
      
      </xsl:stylesheet>