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."
%let pCountry=;
%let pYear=;
*ProcessBody;
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;
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;