How to Generate Your own QR Code in SAS

QA (Quick Response) codes are a popular type of two-dimensional representing information such as geographical coordinates, contact details, URL, text message, or even poem. QR Codes store up to 4,296 alphanumeric characters of arbitrary text. 

They are also known as hardlinks or physical world hyperlinks. QR codes can be read by any appropriate software such as QR code reader or mobile phones.

Generate QR Code in SAS

You can generate your own QR code in SAS using the PROC HTTP procedure from any text input. PROC HTTP enables you to request and receive information from a web service.

Here you’ll invoke PROC HTTP to call a web service for generating QR codes. There are two API methods which I’m aware of that you can use to generate QR code in SAS. You’ll learn further in this article which one to use and why!

  1. Use Google API 
  2. Use goqr QR Code API

Both the API’s work absolutely fine with SAS and create QR code images with user input text. Most importantly, it’s free to use these APIs.

1. Use GOOGLE API to Generate QR Code in SAS

You can use Google API for free to generate QR code in SAS on the fly with a URL GET request. For the demonstration we’ll pass the URL to the PROC HTTP as input text to generate qr code.

The below sas macro allows you to pass any URL you want by defining variable “qr_link” and generate a QR code image at specified folder location.

				/* user input text */
%let qr_link='URL-or-Text-or-Message';

/* path to store QR code image */
filename myqr '/path-to-store-qr-code-image/qr.png';

/* call sas macro to generate QR code */
%to_qr(&qr_link, myqr);

			

We have created a QR code by passing the following parameter to create QR code that points to this article.

				/* user input text */
%let qr_link='www.learnsascode.com/generate-qr-code-in-sas';

/* path to store QR code image */
filename myqr '/path-to-store-qr-code-image/qr.png';

/* call sas macro to generate QR code */
%to_qr(&qr_link, myqr);

			
generate qr code in sas

Here is the SAS macro which is a simplified and modified version of this code from SAS support. You can copy the below code as-is, change the input parameters and that’s it.

You can create as many QR codes as you wish. In fact you can build a small online web or mobile application using this code.

				/***************************************************************************
	1. Use Goggle API to Generate QR code in SAS
		https://developers.google.com/chart/infographics/docs/qr_codes
****************************************************************************/

%macro to_qr(qr_link, myqr);

options noserror;
data _null;
	url_encoded='chs=500x500&cht=qr&chl=' ||
              urlencode(strip(&qr_link)) || '&chld=l';
	put url_encoded=;
	call symputx('qrlink', url_encoded);
	put 'qrlink :' "&qrlink";
run;


proc http in="&qrlink" out=myqr method='post' 
		url='https://chart.googleapis.com/chart?' 
		ct='application/x-www-form-urlencoded';
run;

%mend;

%let qr_link='www.learnsascode.com/generate-qr-code-in-sas';
filename myqr '/home/u61950255/Files/qr.png';
%to_qr(&qr_link, myqr);
			

Warning: This Google API is deprecated though it works absolutely fine for now. You never know when it will stop working and that’s why we have come up with one more method to do the exact same. It’s called goqr QR code API.

2. Use GOQR API to Generate QR Code in SAS

This method works exactly the same as the previous method. The only thing is here you’ll use goqr API to generate QR code. They have very good documentation available here to read more details about this API.

Here also you’ll use PROC HTTP and the slightly modified version of above SAS macro to accommodate the GOQR API call method.

The user parameters remain untouched, but the only difference you’ll find here is with the formation of encoded URL and API URL.

				/* URL Encoded: */
url_encoded='size=500x500&data=' ||
              urlencode(strip(&qr_link));

/* API URL: */
url='https://api.qrserver.com/v1/create-qr-code/?' 

			

This time let’s try to create QR code that points to our blog articles, learnsascode.com/blog by setting the following parameters.

				/* user input text */
%let qr_link='www.learnsascode.com/blog';

/* path to store QR code image */
filename myqr '/home/u61950255/Files/qr2.png';

/* call sas macro to generate QR code */
%to_qr(&qr_link, myqr);

			
sas code to generate qr code

Here is the complete SAS macro that uses the GOQR API and generates QR codes. There is no as such limitations to call this API. 

				/***********************************************************************
	2. Use goqr QR Code API 
		https://goqr.me/api/
************************************************************************/

%macro to_qr2(qr_link, myqr);

options noserror;
data _null;
	url_encoded='size=500x500&data=' ||
              urlencode(strip(&qr_link));
	put url_encoded=;
	call symputx('qrlink', url_encoded);
	put 'qrlink :' "&qrlink";
run;


proc http in="&qrlink" out=myqr method='post' 
		url='https://api.qrserver.com/v1/create-qr-code/?' 
		ct='application/x-www-form-urlencoded';
run;

%mend;

%let qr_link='www.learnsascode.com/blog';
filename myqr '/home/u61950255/Files/qr2.png';
%to_qr2(&qr_link, myqr);
			

I encourage you to create your own QR code using any of these methods that points to your social media account and share with the world. It would be a nice project.

Fun FACT: Scan the below QR code to connect with me on Twitter 🙂

create qr code in SAS with social media link

FAQ

How to create QR code in SAS?

You can use PROC HTTP sas procedure to call web services google API or goqr API and generate QR code in SAS.

Which API to use to generate QR code in SAS?

You can use Google api or goqr api within the PROC HTTP procedure by passing the correct parameters and generate QR codes.

Which SAS procedure to use to generate QR code?

SAS has proc http procedure which you can use to call API and generate QR code. Usually Google API or goqr api’s are being used in SAS to create QR code.