Contents Implementation & Administration Guide 1.1 Previous Next

SAS® Stored Process Coding Example

The following SAS program is an example of a stored process. This program, called prdsale1.sas, is delivered with the SAS Information Delivery Portal application and is part of the demo portal. You can find the source file in the "SASDemos" directory within the portal's installation directory. When you log on to the portal with the user name "portaldemo," the stored process appears in the Reports window as "Product Sales Demo."

The first section of prdsale1.sas, called the prologue, uses the SAS Macro Language to create and initialize a variable for each of the stored process's execution parameters. In this example, the prologue creates the variables pCountry and pYear and initializes them to null values.
%let pCountry=;
%let pYear=;
The next line of code, *ProcessBody, is a marker. This statement is required in order to delineate the boundary between the prologue and the source body.
*ProcessBody;
The next section of code, the data step, reads the input file sashelp.prdsale. The stored process filters the records based on the user-supplied values for the execution parameters pCountry and pYear.
data filter;
set sashelp.prdsale;
if UPCASE(country) = UPCASE(symget("pCountry"));
if year = symget("pYear");
run;
The proc steps sort and tabulate the data. The SAS Output Delivery System (ODS) is used to place the output in an HTML format.
proc sort data=filter;
by country;
run;
ods html close;
filename b temp;
ods html body=b (url="body.htm")
         style=BarrettsBlue;
proc tabulate data=filter;
table country*division,
      actual;
class country division;
var actual;
run;
ods html close;
The final section of code uses call routines from the Publish Framework section of SAS Integration Technologies to publish the report results to the portal. First, the package_begin statement creates the new package. The insert_html statement inserts the HTML file into the package. The package_publish statement sends the package to the requesting application, which in this case is the SAS Information Delivery Portal. The package_end statement then releases system resources from the Publish framework.

For detailed information and additional examples of the use of these call routines, refer to the Publish Package Interface section of the SAS Integration Technologies Web site.
call package_begin(pid, description, nameValue, rc);
if rc ne 0 then do;
  msg = sysmsg();
  put msg;
end;
body="fileref:b";
bodyUrl="body.htm";
frame="";
frameUrl="";
contents="";
contentsUrl="";
page="";
pageUrl="";
nameValue="";
description="Sales Report: Tabular";
call insert_html(pid, body, bodyUrl,
                      frame, frameUrl,
                      contents, contentsUrl,
                      page, pageUrl,
                      description, nameValue, rc);
if rc ne 0 then do;
  msg = sysmsg();
  put msg;
end;
call package_publish(pid, "TO_REQUESTER", rc, "", "");
if rc ne 0 then do;
  msg = sysmsg();
  put msg;
end;
call package_end(pid, rc);
run;

The program in its entirety is displayed below.

%let pCountry=;
%let pYear=;
*ProcessBody;
title "&pYear Sales Report for &pCountry";
data filter;
set sashelp.prdsale;
if UPCASE(country) = UPCASE(symget("pCountry"));
if year = symget("pYear");
run;
proc sort data=filter;
by country;
run;
ods html close;
filename b temp;
ods html body=b (url="body.htm")
         style=BarrettsBlue;
proc tabulate data=filter;
table country*division,
      actual;
class country division;
var actual;
run;
ods html close;
data _null_;
rc = 0;
length description $100 nameValue $100
       body $64 bodyUrl $64 frame $64 frameUrl $64
       contents $64 contentsUrl $64 page $64 pageUrl $64;
NameValue="category=sales context=product";
description="&pYear Sales Report for &pCountry";
call package_begin(pid, description, nameValue, rc);
if rc ne 0 then do;
  msg = sysmsg();
  put msg;
end;
body="fileref:b";
bodyUrl="body.htm";
frame="";
frameUrl="";
contents="";
contentsUrl="";
page="";
pageUrl="";
nameValue="";
description="Sales Report: Tabular";
call insert_html(pid, body, bodyUrl,
                      frame, frameUrl,
                      contents, contentsUrl,
                      page, pageUrl,
                      description, nameValue, rc);
if rc ne 0 then do;
  msg = sysmsg();
  put msg;
end;
call package_publish(pid, "TO_REQUESTER", rc, "", "");
if rc ne 0 then do;
  msg = sysmsg();
  put msg;
end;
call package_end(pid, rc);
run;


Contents Implementation & Administration Guide 1.1 Previous Next