Translating Ruby to SAS (or vice-versa)

I’ve just been hired on a project that uses SAS and I know nothing but SPSS, but I know that really well. Can I come over to your office tomorrow?

… so began a very interesting afternoon, where the new employee would show me code that she had written, say VALUE LABELS and ask, “Can you translate that to SAS?” and I would tell her about PROC FORMAT.  In a few hours, we breezed through the basic statements and finished up with regression.

I was confused when, in my first year of college, professors and classmates alike assured me that it really did not matter what programming language I took, because they’re all pretty much alike. Of course not all languages are interchangeable but I do now get the point – if you’ve never programmed before, a lot of what you have to learn, like re-usable code – whether you call it a macro, a method or a subroutine – is going to transfer to any other language. You’ll have variable types, arrays, functions, loops. I think I had pretty smart professors who refused to let us learn computer science in the abstract. You had to use a language, but they were right, it really didn’t matter which one.

The most fun part of Ruby, if you ask me, which you didn’t, but when has that ever stopped me, is defining methods, which if you’ve ever coded a SAS macro, you already understand. Defining a method looks like this

def methodname(parameters)

— lines of whatever you want the method to do


To call the method, you type

methodname(parameter values)

If you are used to writing macros, you are already translating this in your head to something like

%macro readfile(dsn,outfile) ;

Data lib..outfile ;

set &dsn ;

keep id total ;

%mend ;

%readfile(lib2.myfile, outfile) ;

Of course, if you have never written a SAS macro you may have no idea what I am rambling on about. Join the club.

I’ve been having a lot of fun with Ruby. While there are lots more upsides, two down sides need to be pointed out:

1. I was wrong. I hate that. Last year, Mark Stevens wrote a blog on Zero to SAS Certified in 3 months and I questioned what good was a certification you could get in three months. He explained that he had learned Fortran, C and VBA. I do understand how you could learn one programming language at the basic level in studying for 50 hours if you came in with a good understanding of how things work.

2. There are some things in Ruby (like the ubiquitous curly brackets) that are going to throw off SAS users. Two level names mean something completely different in Ruby.

page1.length  Does NOT indicate a two-level name with page1 as the directory and length as the file. When you see construction like this, the first thing is an OBJECT and the second is the action being performed on that object. So page1.length will (not surprisingly)  return the length of the object page1. Even though it is a switch from the syntax you are used to, I mean, come on, it’s so friggin’ obvious – fname.capitalize is going to capitalize the first letter of fname, name.upcase is going to put name in uppercase

Overall, I think there ought to be more of a push for people to branch out and learn new languages just for the hell of it, preferably one that is somewhat different than what you are used to. The similarities make it easy to learn while the differences, like the way Ruby handles arrays and variable definitions, make it worth learning.

Speaking of learn, I read an interesting paper by Gongwei Chen about SAS certification, where he discussed the benefit of getting certified as an advanced programmer even though he had ten years of experience.

I’m debating the idea of taking a Ruby certification exam, not because I think it will get us more business or impress my friends, but for the reasons that Gongwei mentioned in his paper. He said that it forced him to concentrate the time he spent studying and trying new programming techniques, because he had a target, and that, even though he had been programming for ten years, he used a defined subset of procedures and taking the exams forced him to broaden his view. I’d never really thought of certification in those terms before, and it was an intriguing perspective.

Similar Posts


  1. I am a longtime SAS programmer that gets motivated every now and then to learn and use new languages.
    In a typical consulting day I will use:
    SAS on Unix
    SAS on PC, both using BASE/Macro, SCL, Connect, etc
    Visual Studio .NET w/VBA
    various Unix tools and scripting
    Ruby, Ruby on Rails, JQuery, MySQL, etc.

    From my experience you are correct, it is all pretty much the same: loops, data structures and logic. But for sure, Ruby is the most fun. And Ruby on Rails is insanely productive (once you get your environment set up correctly!).

  2. Hi! If you will need to translate a Rail app into many languages, there’s a good online software localization tool like POEditor that I suggest giving a shot, because it has a simple user interface. The tool doesn’t support .yaml formats, but you can convert them to po files with the help of this free converter tool like http://yml2po.com/. I think it might worth trying.

Leave a Reply

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