Sample 60964: Creating a SAS® stored process and executing it as a RESTful SAS® BI web service
These examples illustrate how to create a simple stored process and execute it as a RESTful SAS BI Web service.
EXAMPLE 1: JSON Output
In this example, JSON output is sent back to the client application.
- Create a stored process called web_service_test that contains the following code:
proc json out=_WEBOUT;
export sashelp.class;
run;
In this example, web_service_test was saved in the /Examples metadata folder. So, the path is /Examples/web_service_test.
- On the Execution tab in the stored process Properties window, select Stream (instead of Package) for Result Capabilities.
- Execute the stored process web service using the HTTP procedure by submitting the following code:
filename resp "c:\temp\web_service_test.txt";
proc http
url="http://hostname:port/SASBIWS/rest/storedProcesses/Examples/web_service_test/dataTargets/_WEBOUT"
out=resp;
run;
In the code above, you must provide the values for hostname and port as well as the correct path to the web_service_test stored process.
Notice dataTargets/_WEBOUT at the end of the URL. The _WEBOUT value corresponds to the proc json out=_WEBOUT specification in the stored process code.
Note: You can also execute the stored process web service by submitting the following request using your web browser:
http://hostname:port/SASBIWS/rest/storedProcesses/Examples/web_service_test/dataTargets/_WEBOUT
EXAMPLE 2: HTML Output
In this example, HTML output is sent back to the client application.
- Create a stored process called web_service_test2 that contains the following code:
%stpbegin;
proc print data=sashelp.class;
run;
%stpend;
In this example, web_service_test2 was saved in the /Examples metadata folder. So, the path is /Examples/web_service_test2.
- On the Execution tab in the stored process Properties window, select Stream (instead of Package) for Result Capabilities.
- Execute the stored process web service using PROC HTTP by submitting the following code:
filename resp "c:\temp\web_service_test2.html";
proc http
url="http://hostname:port/SASBIWS/rest/storedProcesses/Examples/web_service_test2/dataTargets/_WEBOUT"
out=resp;
run;
EXAMPLE 3: Data Target Output
In this example, the output is sent back to the client application using an output Data Target that you define.
- Create a stored process called web_service_test3 that contains the following code:
proc json out=OUTSTR;
export sashelp.class;
run;
In this example, web_service_test3 was saved in the /Examples metadata folder. So, the path is /Examples/web_service_test3.
- On the Execution tab in the stored process Properties window, select Stream (instead of Package) for Result Capabilities.
- Select the Properties for the stored process. Then, click the Data tab, and create a new Target.
- For the Target, specify the following:
Type: Generic Data Target
Label: OUTSTR
Fileref: OUTSTR
Expected content type: application/json
- Execute the stored process web service using PROC HTTP by submitting the following code:
filename resp "c:\temp\web_service_test3.txt";
proc http
url="http://hostname:port/SASBIWS/rest/storedProcesses/Examples/web_service_test3/dataTargets/OUTSTR"
out=resp;
run;
In the code above, you must provide the values for hostname and port as well as the correct path to the web_service_test3 stored process.
Notice dataTargets/OUTSTR at the end of the URL. The OUTSTR value corresponds to the proc json out=OUTSTR specification in the stored process code and to the OUTSTR that was specified for the FILEREF for the target on the Data tab.
EXAMPLE 4: Parameters to Stored Process and JSON Output
In this example, two parameters are passed to the stored process web service and JSON output is returned to the client.
- Create a stored process called web_service_test4 that contains the following code:
%global num1 num2;
data test;
num1 = &num1 +0;
num2 = &num2 +0;
sum=num1 + num2;
run;
proc json out=_WEBOUT;
export work.test;
run;
In this example, web_service_test4 was saved in the /Examples metadata folder called. So, the path is /Examples/web_service_test4.
- On the Execution tab in the stored process Properties window, select Stream (instead of Package) for Result Capabilities.
- Select the Properties for the stored process. Then, click the Parameters tab.
- Create the following parameters for the stored process:
name: num1 prompt type: text
name: num2 prompt type: text
- Execute the stored process web service using PROC HTTP by submitting the following code:
filename input TEMP;
data _null_;
file input;
input rec $80.;
put rec;
cards4;
<stp>
<parameters>
<num1>11</num1>
<num2>22</num2>
</parameters>
</stp>
;;;;
/* The 4 semicolons must be in columns 1-4 */
filename resp "c:\temp\web_service_test4.txt";
proc http
url="http://hostname:port/SASBIWS/rest/storedProcesses/Examples/web_service_test4/dataTargets/_WEBOUT"
in=input
out=resp;
headers "Content-Type"="application/xml" "Accept"="application/json";
run;
In the code above, you must provide the values for hostname and port as well as the correct path to the web_service_test stored process.
In this example, the parameters num1 (which has a value of 11) and num2 (which has a value of 22) are passed to the stored process.
More Information
For more information, see the following:
SAS® 9.4 BI Web Services: Developer's Guide
SAS Sample Note 63405, "Creating a SAS® stored process and executing it as a RESTful SAS® BI web service: Part 2"
SAS Sample Note 63438, "Creating a SAS® stored process and executing it as a RESTful SAS® BI web service: Part 3"
SAS Sample Note 63463, "Creating a SAS® stored process and executing it as a RESTful SAS® BI web service: Part 4"
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
These examples illustrate how to create a simple SAS® stored process and execute it as a RESTful SAS BI web service.
Date Modified: | 2019-01-14 14:57:54 |
Date Created: | 2017-08-24 16:12:58 |
Operating System and Release Information
SAS System | SAS Integration Technologies | Microsoft® Windows® for x64 | 9.4 | | 9.4 TS1M0 | |
Microsoft Windows 8 Enterprise x64 | 9.4 | | 9.4 TS1M0 | |
Microsoft Windows 8 Pro x64 | 9.4 | | 9.4 TS1M0 | |
Microsoft Windows 8.1 Enterprise 32-bit | 9.4 | | 9.4 TS1M0 | |
Microsoft Windows 8.1 Enterprise x64 | 9.4 | | 9.4 TS1M0 | |
Microsoft Windows 8.1 Pro 32-bit | 9.4 | | 9.4 TS1M0 | |
Microsoft Windows 8.1 Pro x64 | 9.4 | | 9.4 TS1M0 | |
Microsoft Windows 10 | 9.4 | | 9.4 TS1M0 | |
Microsoft Windows Server 2008 R2 | 9.4 | | 9.4 TS1M0 | |
Microsoft Windows Server 2008 for x64 | 9.4 | | 9.4 TS1M0 | |
Microsoft Windows Server 2012 Datacenter | 9.4 | | 9.4 TS1M0 | |
Microsoft Windows Server 2012 R2 Datacenter | 9.4 | | 9.4 TS1M0 | |
Microsoft Windows Server 2012 R2 Std | 9.4 | | 9.4 TS1M0 | |
Microsoft Windows Server 2012 Std | 9.4 | | 9.4 TS1M0 | |
Windows 7 Enterprise x64 | 9.4 | | 9.4 TS1M0 | |
Windows 7 Professional x64 | 9.4 | | 9.4 TS1M0 | |
64-bit Enabled AIX | 9.4 | | 9.4 TS1M0 | |
64-bit Enabled Solaris | 9.4 | | 9.4 TS1M0 | |
HP-UX IPF | 9.4 | | 9.4 TS1M0 | |
Linux for x64 | 9.4 | | 9.4 TS1M0 | |
Solaris for x64 | 9.4 | | 9.4 TS1M0 | |