SAS Programming with VIM

SAS Programming with VIM

While I'm an old time vi user, I have been really using Emacs in some sort of vi mode since 1995. I wrote this article when I felt tempted to give VIM a chance. I'm sorry to say that Vim lost and I went back to Emacs very shortly after.

If you are interested in programming SAS on Vim, this is still a relevent article. But realize that I do not use this.

I've used some version of vi for all of my editing since I first learned Unix in 1980. Vi is criticized for being difficult to use, but for those that endure the learning curve, it's the fastest editor around. In the last 20 years, vi has been usurped by Vim, "vi improved". Mostly, that means it has lots of new capabilities and it's keeping up with the times. Tabbed windows, split windows, code completion, syntax checking, testing units, code tagging, folding, SFTP-- you name it, Vim probably has it. It has so many add-ons, it can be a chore figuring out what works best for you. I've recently been working with some pretty modern IDE's which have nothing on Vim. In fact, I've given up on them in favor of Vim.

I was a steady user of vi until I started work at SAS in 1995. Everyone I worked with used Emacs. The entire development environment was integrated with Emacs. So I switched, but I used viper-mode which made Emacs act like vi. I maintained and coded a lot of elisp code during my years at SAS, including everything from parsing error logs, managing environment variables, compilers, debuggers, to syntax highlighting, including this Tagset mode.

But Emacs at SAS suffered greatly from neglect. Over the years, it became less and less capable and I found myself looking back at vi. I've been tweaking my Vim environment for the last couple of years. But lately, I've needed to get my Vim work environment into shape. SAS programming with Vim was just not up to par.

So here I am up to my elbows in Vim code. I have been unaware of my suffering in my ODS Tagset work these last couple of years. It must have hurt a little bit when I switched from Emacs, but I got used to it. Recently, after working a fair amount in Python and PHP, which have very nice coding environments, I decided it was time to do something about it. Comparatively working on SAS code was an awful experience. It took me longer than I would have liked, I had to learn Vim Script. I now have syntax highlighting and automatic indention for ODS Tagsets. In Vim, code completion almost works like magic, although I'm already working on improving it for SAS.

If you are wanting to do something similar for another language, both the indent and syntax files for tagsets are about as simple as any I've seen, and I've seen a lot.

While I was at it I did some research and found syntax and indention for SAS code, and a couple of functions that allow running SAS on the current buffer and checking the log for errors, warnings, notes, etc.. Since it took a fair amount of time and work hunting everything down and putting it all in the right places, I've packaged all of it up on my github in a repository named SAS-Vim.

I use Vundle to manage all of my Vim plugins and I highly recommend it. Add Bundle "EricGebhart/SAS-Vim" to your list of bundles, do a :bundleupdate and you'll be in business with some nice syntax highlighting, indention and running batch jobs right from your editor window. Check the documentation for the package for recommended key mapping.

If you are still using stock Vim, and haven't installed any add-ons, I recommend you start by installing Steve Francia's SPF-13. This vim setup has a ton of features without actually breaking anything like some of the other more expansive setups like Janus or Cream. Both of which either do to much or try to protect the novice user from the somewhat steep learning curve of  Vim. Depending upon your personal history with vi and other editors you may like one them.  Although for me, Steve's setup was the best because it provided a lot of value, and gave me an easy way to extend and modify it. Which I have. The setup is clean and easy. Be sure to read the documentation.

SAS programming with Vim creates a development environment that rivals all others and is customizable beyond belief. Adding in a few extra packages for such as neocomplcache for code completion, Git, svn and cvs support, a ctags taskbar, and tasklist for todos and fix this, and you could have a superior SAS development environment that puts all the others to shame.

I haven't stopped yet, this is just the beginning. I'm working on neocomplcache settings for SAS code, and I have other tools for managing remote projects, remotely running batch code and code snippets, and log processing for errors.  As these development tools become more polished I'll be sharing them with you here. So come back to see what else I've been up to. Let me know what you think in the comments.



  1. What a wonderful post, which helps me a lot. Thanks.

    I just noticed that you use some old sas.vim. It would be great that you would like to use the updated sas plugins.

    Vim will throw a error during starup, it seems that it is related to tpl.vim. I think I did not configure vimrc correctly. Would you share your .vimrc on github, thanks.

    • When I tried to edit (any *.vim), which is caused by your added tpl.vim.
      Error detected while processing BufRead Auto commands for “*”:
      E492: Not an editor command: SetTagsetFileType()
      Press ENTER or type command to continue

      Another problem is related to syntax/sas.vim. I have to replace it with the new one. The old one has issues related to dos and unix file format. After replaced it with the new one, editing sas is kind of OK.

    • Sure thing. I’ll update mine to the new ones.
      Thanks for pointing those out.

Leave a Reply

Your email address will not be published. Required fields are marked *