As a side project I wrote a simple macro in SAS to add syntatic sugar to SAS code. I hate how verbose SAS is sometimes!

So my macro looks like this

%macro md(code);
    /* expects a superquoted string */
   * append a b;
   %if %lowcase(%scan(&code.,1)) = append %then %do;
        proc append base = %scan(&code.,2) data=%scan(&code.,3); run;

Instead of writing

proc append base=a data=b; run;

to append two datasets, I can simply write

%md( append a b);

This got me thinking. Since I work with SAS all day and I enjoy programming. Why not (for fun) design a new data processing language that compiles to SAS?! As many of you can guess this idea was inspired by CoffeeScript which compiles to Javascript.

I learnt that CoffeeScript was initially written in Ruby? But why? How did the author choose Ruby? What are the things to consider in choosing a language? And what resources are available that might be useful in pursuing this?

  • CoffeeScript is very ruby-esque. I would imagine that the choice had a lot to do with personal preference. There is also this. – Robert Harvey Jun 11 '13 at 22:40
  • Instead how about implementing a parser interpreter for SAS that compiles to SOMETHING else or runs WITHOUT sas installed (and you can add your syntactic sugar on top of that)? – Jay Stevens Jun 21 '13 at 2:17
  • Interesting. I am also trying to write a SAS data step compiler that compiles to R. However, it's difficult to replicate the "infrastructure" already in place in SAS. There's a reason why a lot of programming languages nowadays compiles into Javascript (or can be used with JVM). Most browsers can run Javascript. But not many (if any) can run CoffeeScript natively, as nice as CoffeeScript is, getting all those browsers onboard will be a long and difficult process. Hence it's better to just compile to Javascript first and now your language has access to all of the existing Javascript resources. – xiaodai Jun 21 '13 at 9:33
  • I would think a language like Ruby or Python might be useful. I was going to initially say C or C++, as what you are going to need to do is to write a compiler, which C is perfect for. I'm not sure you even need a compiler for a project like this. What you just need is a parser that can change the code from your 'Cool-SAS' into normal SAS. You won't be able to run it without SAS though, so maybe building a parser that transforms your input into SAS output, which you copy/paste into SAS might work. – Joe Nov 19 '13 at 20:06
  • You don't say which languages you already know, meaning we have no idea how large and heavy your blinders may be. If you do not already know LISP, start there. You may find that it will be far easier to do what you want to do using LISP, rather than a more "conventional" language. – John R. Strohm Oct 19 '16 at 22:00

Your simplified language will use no/few options, so will be very limited.

For example, no "force" option in your append macro.

If you want a richer language, your macros will become ... the sas language.

It is usual and common to write macros that do many things, not just replace 7 words

proc append base=a data=b; run;

with 3 words.

%md( append a b);

Where are the savings in that? You save 3 words and lose all the options.

A better use for macros is to do more complex things, like finding the top-10 values and plotting them, or sorting and de-duping a macro list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.