Five SAS programming language features you should be using


Good news -- the SAS program that you wrote and put into production 10 years ago still works. Hey, it's SAS, so you probably take that for granted. But are those techniques from 2008 still the best way to accomplish your task? SAS 9.4, first released in 2013 and now refreshed with its sixth maintenance release, continues to extend the SAS programming language. New features allow you to simplify your code, make it run faster, and erase some of that technical debt you've been carrying due to previous workarounds or limitations.

The reason that I'm writing this post now is to recognize the next chapter for my long-time colleague, Rick Langston. After 38 years at SAS (and more time as a SAS user before that) Rick is retiring from his role. Many of you know him as a major steward of the SAS programming language. And many of the tips that I've shared on this blog are made possible by Rick's work. Here's an interview that I hosted with Rick in 2013, just before SAS 9.4 was first released.

Five cool features of the SAS language: the details

In the above video, Rick talks about three SAS features that were first introduced in 2013. I've added a couple of more recent items to the list to round it out.

FILENAME ZIP access method

This brings the ability to read and write compressed ZIP files, and GZIP files, directly into the SAS language. Use this feature to replace the clunky (and not always feasible) calls into external tools such as gzip, WinZip, or 7-Zip. In SAS, a "native" FILENAME access method is more portable and robust than calling out to an external tool with FILENAME PIPE.

For more information, check out the many SAS blog posts with examples that I've shared over the years.

DOSUBL function

Have you ever wanted to run another SAS procedure from inside of a DATA step? Rick calls this "submitting SAS code on the side", as it allows you to run a SAS step or statement from within a currently running step. You can learn more from the DOSUBL function reference, or from this SAS Global Forum paper by Rick. I've also written a post with a specific example in SAS Enterprise Guide.

LOCKDOWN system option and statement

This one will excite SAS administrators. You can set the LOCKDOWN system option in a batch SAS session or SAS Workspace server to limit some of the "dangerous" functions of SAS and, more importantly, limit the file areas in which the SAS session will operate. Read more in this article, Fencing in your SAS users with LOCKDOWN.

Creating and managing directories within SAS

This technique combines two features into a one-two punch of file folder management. Use the DLCREATEDIR option and the LIBNAME statement to create a new directory, and then use the DLGCDIR function to change the current directory of the SAS session.

In the past, you would have had to issue operating system commands to create a new directory and then switch ('cd') into it. That approach is not portable across different operating systems, and it requires access to the operating system shell -- not available in many SAS sessions these days. See these blog posts for more information and examples about the new techniques:

Using %IF/%THEN/%ELSE in open code

Perhaps the most life-changing of all of these SAS language updates, you can now use simple if-then-else logic for program flow, outside of the confines of the SAS macro language. It's what makes defensive programming like this possible -- without having to wrap the logic in %MACRO/%MEND:

%if %symexist(config_root) %then %do;
  filename config "&config_root./config.json";
  libname config json fileref=config;
  data _null_;
   set config.root;
   call symputx('tenant_id',tenant_id,'G');
   call symputx('client_id',client_id,'G');
   call symputx('redirect_uri',redirect_uri,'G');
   call symputx('resource',resource,'G');
%else %do;
  %put ERROR: You must define the CONFIG_ROOT macro variable.; 

Read more here: Using %IF/%THEN/%ELSE in SAS programs.

A legacy in the making

I'm going to miss having Rick Langston as a SAS colleague. There aren't many other people who know how to spin up a version of SAS from 30 years ago to help me track down a curious question. However, I'm not worried about the future of the SAS language. Rick has been excellent about sharing his knowledge for decades (just check his annual contributions to SAS Global Forum), and his team is well-suited to carry on the work of extending the SAS programming language for the next generation of SAS users. Thanks to Rick for helping to build such a solid foundation.


About Author

Chris Hemedinger

Director, SAS User Engagement

+Chris Hemedinger is the Director of SAS User Engagement, which includes our SAS Communities and SAS User Groups. Since 1993, Chris has worked for SAS as an author, a software developer, an R&D manager and a consultant. Inexplicably, Chris is still coasting on the limited fame he earned as an author of SAS For Dummies


  1. I can’t believe it - SAS without Rick?!? I’ve used every one of these techniques in my code, and thanked heavens for them more than once. Rick - you’ll be sorely missed! With apologies to Douglas Adams, So long, and thanks for all the SAS :-)

  2. I agree I can't imagine SAS without Rick! All the best Rick in your next adventure! Merry Christmas too!

  3. Hi All.

    I stumbled on this blog and can't believe there will be SAS after Rick. Many years ago, I was working on a SAS programming book and was confused about an obscure feature of PROC FORMAT (I believe it was called enhanced numeric informat - where you can read both text and numerics in one step resulting in a numeric value). As a SAS author, I had access to SAS developers. I called SAS tech support and I was transferred to Rick as the expert on PROC FORMAT. Rick told me "When I wrote PROC FORMAT . . .." I was speaking to the guy who wrote PROC FORMAT! That was like speaking to GOD!/ Since that time I have become friends with Rick and it is impossible to imagine the contributions he has made to SAS in his years there. Best of luck Rick!

    • Chris Hemedinger
      Chris Hemedinger on

      Ron, maybe you and Rick can plan a post-retirement road show about SAS functions -- the guy who wrote the functions, and the guy who taught the world to use them.

      Actually, I think John Sall had ownership of PROC FORMAT before Rick got it. But I'm sure that Rick had the opportunity to *rewrite* it when everything was reimplemented in C.

      Well, I guess John can take it back, if he wants. But fortunately, Rick has done a great job of making sure that the very capable developers here know how to pick up where he left off.

  4. Chris, I missed this blog post when it came out last month so I'm late to the party, but want to add my voice. Thank you, Chris, for once again sharing the "news we can use," and congratulations and good luck to Rick on his retirement! Rick came (multiple times, I think) to speak to SAS users in Sacramento, and I always sought Rick out at SAS conferences for advice and news about the latest and greatest in SAS programming. I too cannot imagine SAS without Rick, but Rick's impact has been so great (at least for me) that he will always be a part of this community. People like Rick can't really leave no matter where they go or what they do. Neither gone, nor forgotten. best, Susan

    • Chris Hemedinger
      Chris Hemedinger on

      Thanks Susan. Good news -- Rick *is* scheduled to come to SAS Global Forum in Dallas this year. It will be odd for him to attend as a "civilian" -- but be sure to seek him out and get your questions in, for old times' sake.

  5. The ability to create and manage directories without directly interfacing the OS is fantastic! Thanks Chris!

Back to Top