PROC HTTP enables you to request and receive information from a web service.
This sample uses PROC HTTP to generate a Quick Response (QR) code from any text input. A QR code is a type of two dimensional barcode representing information such as geographical coordinates, contact information or a URL. A QR code can be read by a mobile phone or another QR-code-enabled device.
Base SAS® offers two procedures for accessing web services: PROC HTTP and PROC SOAP. Use PROC HTTP for RESTful web services. For SOAP-based web services, use PROC SOAP. Both procedures are available beginning in SAS 9.2.
To call a web service with PROC HTTP, you specify options that include a fileref for the input data, a fileref for the output and a URL address for the request.
This sample shows a SAS macro that invokes PROC HTTP to call a web service for generating QR codes. The macro has two parameters: a fileref for the input and a fileref for the output which is a PNG file.
The first data step in the macro reads the input fileref and generates a string of attributes required by the web service. The attribute string is saved as a character variable in a temporary dataset. The variable's length is stored in a macro variable called "qrtextl".
The second data step writes this dataset to a text file. Taking this text file as input, PROC HTTP calls the web service. The macro variable "out" names the fileref where the output is written.
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.
/* Have whatever text you want in the first fileref, and reference a PNG file in the second fileref. Use this macro to produce a QR image of the text. You can have up to 4K of text in the input file.
For example:
filename mypgm 'mypgm.sas';
filename myqr 'qr.png';
%to_qr ( mypgm , myqr );
*/
%macro to_qr(in,out);
/*this data step generates a string of attributes required by the web service.*/
data; infile &in recfm=f lrecl=4096 length=l;
length url_encoded $8192;
keep url_encoded;
input @1 all $varying4096. l;
url_encoded = 'chs=500x500&cht=qr&chl=' ||
urlencode(strip(all)) || '&chld=l';
call symputx('qrtextl',length(url_encoded));
output; stop;
run;
filename qrtext temp recfm=f lrecl=&qrtextl;
/* This data step writes to a text file the input that PROC HTTP will use to call the web service. */
data _null_;
set;
file qrtext;
put url_encoded;
run;
proc delete; run;
/*call the web service*/
proc http in=qrtext out=&out method='post'
url='https://chart.googleapis.com/chart?'
ct='application/x-www-form-urlencoded';
run;
filename qrtext clear;
%mend;
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.
Type: | Sample |
Date Modified: | 2012-03-08 08:40:52 |
Date Created: | 2012-02-07 10:29:40 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | Solaris for x64 | 9.2 TS1M0 | |
Linux for x64 | 9.2 TS1M0 | |||
Linux | 9.2 TS1M0 | |||
HP-UX IPF | 9.2 TS1M0 | |||
64-bit Enabled Solaris | 9.2 TS1M0 | |||
64-bit Enabled HP-UX | 9.2 TS1M0 | |||
64-bit Enabled AIX | 9.2 TS1M0 | |||
Windows Vista for x64 | 9.2 TS1M0 | |||
Windows Vista | 9.2 TS1M0 | |||
Microsoft Windows XP Professional | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |||
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |||
OpenVMS on HP Integrity | 9.2 TS1M0 | |||
Microsoft® Windows® for x64 | 9.2 TS1M0 | |||
Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |||
z/OS | 9.2 TS1M0 |