Remember the quote from the documentation back at the beginning of the chapter that said in essence that all you need is a service name and a program name? This is what they were talking about. The parameters are appended to the URL just as we saw in the Perl program in Chapter 5. The Application Broker passes a request for SAS program code to the Application Server, which locates the program, executes it, and sends the result back to the broker. (Actually, the _service parameter is not required if the DefaultService directive is set in the broker.cfg file and you want to use that service.)
Changing the value of the _program parameter runs a different program. For example, Display 6.9 shows another familiar-looking Web page. As the display illustrates, the URL for this page (all in one line in the browser) is as follows:
http://hunding/scripts/broker.exe?
_service=default&
_program=sample.webhello.sas
Note that on Windows the URL is not case-sensitive, while on a UNIX system it would be.
Display 6.9 SAS/IntrNet Samples: Hello World!
In this example the URL includes a new value for the _program parameter:
sample.webhello.sas. The webhello.sas sample program, along with a number of others, is supplied with the SAS/IntrNet software. On UNIX servers these are installed by default in the directory $SASROOT\samples\IntrNet; on Windows the directory is
$SASROOT\IntrNet\sample (go figure). The program name must include three levels:
sample is the name of the program library (not the directory; see Example 6.1), while webhello.sas is the filename of the program itself. The program code is shown in Example 6.1:
Example 6.1 SAS/IntrNet: Hello World
/*simply write out a web page that says "Hello World!"*/
data _null_;
file _webout;
put '<HTML>';
put '<HEAD><TITLE>Hello World!</TITLE></HEAD>';
put '<BODY>';
put '<H1>Hello World!</H1>';
put '</BODY>';
put '</HTML>';
run;
This simple program illustrates how easy it is to create HTML using the Application Dispatcher. The most important line in the DATA step is the highlighted one, defining the file reference for the output as _webout. This is a SAS FILEREF that is
automatically defined for you when the Application Server starts, indicating that the output of the PUT statements should be sent to the Web client. SAS/IntrNet software automatically takes care of inserting the correct mime-type header and sending the code back to the client browser.
Chapter 6 SAS/IntrNet: the Application Dispatcher 115
Of course, usually one needs to send more parameters to the server than just the name of the program. The Application Dispatcher simply translates all the name/value pairs into macro variables that are passed to the SAS program; this is the SAS equivalent to the Perl parameter() function described in the preceding chapter. In fact, we can recreate the temperature conversion program easily in SAS as follows:
Example 6.2 SAS/IntrNet: Temperature Conversion Program
/* SAS/IntrNet program to convert F to C and vice versa */
data _null_;
file _webout;
***** write generic XHTML header *****;
put '<?xml version="1.0" encoding="utf-8"?>'/
'<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML Basic 1.0//EN"'/
' "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">'/
'<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">';
***** write top of page *****;
put '<head>'/
'<title>SAS/IntrNet Temperature Conversion Calculator</title>'/
'</head>'/
'<body>'/
'<div style="text-align: center">'/
'<h1 style="color: blue">Temperature Conversion Calculator</h1>';
**** create HTML form * with hidden text fields ***;
put '<form name="calculator" action="' &_URL '" method="get">'/
'<input type="hidden" name="_service" value="default" />'/
'<input type="hidden" name="_program" value="' &_program '"/>';
***** get parameter values *****;
temp = symget('input');
type = symget('convert');
***** input temperature *****;
put '<p><strong>Enter a temperature and select a conversion type: </strong>'/
'<input type="text" name="input" value="' temp '"/></p>';
***** select conversion/compute result *****;
put '<p><input type="radio" name="convert" value="1"' @;
if (type = '1') then do;
put 'checked="checked"' @;
result = 5*(input(temp,8.) - 32)/9;
end;
put '> Fahrenheit to Centigrade</p>';
put '<p><input type="radio" name="convert" value="2"' @;
if (type = '2') then do;
put 'checked="checked"' @;
result = 9*input(temp,8.)/5 + 32;
end;
put '> Centigrade to Fahrenheit</p>';
***** Submit button *****;
put '<p><input type="submit" value = "Submit"></p>';
***** Display results *****;
if (temp > ' ') then do;
put '<p><strong>Result: </strong>'/
'<input type="text" name="result" value="' result 6.2 '"/></p>';
end;
**** write bottom of page *****;
put '</form>'/
'</div>'/
'</body>'/
'</html>';
run;
Comparing this program to the Perl version in the previous chapter, we can see a number of evident differences:
SAS includes the mime-type header automatically; in Perl the header function is required.
Perl has start_html and end_html functions that simplify HTML housekeeping chores, while in SAS these must be done explicitly.
SAS requires the _webout file destination to send output back to the Dispatcher.
SAS uses special reserved macro variables for parameters, shown in bold:
_program is the name of the Dispatcher program that the Application Server should run, while _url is a reference to the Application Broker CGI program (see http://support.sas.com/rnd/web/intrnet/dispatch/reffield.html for a list of the reserved variables available in the Application Dispatcher).
Overall, however, the Perl and SAS programs have the same effect, as shown in Display 6.10, where the URL points to the code in Example 6.2:
http://hunding/scripts/broker.exe?
_service=default&
_program=sample.example6-2.sas
Chapter 6 SAS/IntrNet: the Application Dispatcher 117