How to create your own QR codes with SAS!


You've seen the QR codes that you can just scan in with your smartphone's camera, rather than writing down a web URL or other information, right? But do you know how to create your own QR code? Here's an easy way to create them, using SAS...

You're probably familiar with UPC barcodes, which have been around for many years. Here's an example of a nice traditional barcode (do you know what item this barcode is for?)


In the 1990s, a new two-dimensional/matrix barcode which could hold much more information became popular. It was called a Quick Response Code (or QR code). You can encode many kinds of information in a QR code, and then people can point their smartphone camera at it and have access to the information, without having to write it down. A simple and useful type of information I like to encode into a QR code is a URL - you can then put the QR code on a flier, poster, or demo booth, and people who are interested in your topic can point their smartphone at the QR code and go directly to your webpage (without the user/customer having to type the URL).

Here's an example of a QR code I created with SAS. This one will take you to the URL for a club I'm in. If your smartphone doesn't have a QR code reading app, you might try using Bakodo. (Anybody got recommendations for other good QR code reading apps?)


How did I create the above QR code? ... Well, I put the text for the URL in the file qr_rdbc.txt, ran the code below, and the QR code appears in the file qr_rdbc.png. Could it get any simpler?!?

filename mytext "qr_rdbc.txt";
filename myqr "qr_rdbc.png";
%to_qr ( mytext , myqr );

Similarly, here's a QR code I created for the website where I keep all my SAS examples. Have you got a QR code scanning app installed? Are you able to scan these QR codes and go to the webpages?


Here's a link to my full code that sets up the above macro. The code is a slightly modified version of the following SAS tech support example, which uses a Google chart api. Note that the api is technically deprecated but still works (so far).

What have you used QR codes for? Perhaps something clever you'd like to share? Are you able to create those QR codes using the SAS macro?



About Author

Robert Allison

The Graph Guy!

Robert has worked at SAS for over a quarter century, and his specialty is customizing graphs and maps - adding those little extra touches that help them answer your questions at a glance. His educational background is in Computer Science, and he holds a BS, MS, and PhD from NC State University.

Related Posts


  1. Hi Robert,

    Thanks for sharing your code. Is there a way to control the dimensions of the PNG file that is created by the google website?


    • In Robert's %to_qr() macro, in the url_encoded variable of the data step, you will see "chs=500x500". The is the final dimensions of the QR code. You can either modify the dimensions in the macro, or modify the macro to pass in these dimensions and set them on this variable.

  2. Is it feasible to embed personal QR code in eDM? every receiver get different QR code in the email or SMS

    • Robert Allison

      I think you could. For example, you could put the code that creates the QR code in a SAS macro, and then loop through your data (names/addresses/etc) and create a unique QR code for each one, and then mail that QR code.

  3. The following step is throwing the below Note:

    proc http in=qrtext out=&out method='post'

    NOTE: The SAS System stopped processing this step because of errors.

    Any ideas how to fix it?

    • Robert Allison

      Hmm ... I've never seen that problem when running this code, so I'm not sure how to help you there.

      It will probably be quickest for you to contact SAS Tech Support, and they will probably want to see your whole SAS program, and the whole Log, and to know how you're trying to run it (batch, dms, through EG, etc). And perhaps what kind of network you're on.

Back to Top