SAS Syntax: Best Practices

There are so many different ways to write your SAS code or syntax.  After working in SAS for a few decades now I would like to offer a series of Best Practices when it comes to writing your own syntax.  Remember that how you write your syntax or code is up to you as long as it works – right 🙂

  1. At the end of any DATA step or PROC – add a Run; statement.  This will allow you to select pieces of your code to run separately from your whole program.
  2. Always specify the name of the dataset you are using when running a PROC.  This avoids any confusion in the results when you run parts of your program.  SAS will run any analysis on the last dataset SAS used or created – which may not be the one you want it to use
  3. When using PROC GLIMMIX, take advantage of the * or the commenting ability of SAS.  Include all of your models in the PROC, but add a * in front of all the model statements you are not using at the moment.  For example:
    • Proc glimmix data=flowers plots=studentpanel;
          class block trmt;
          model count_flower = trmt; 
          * model prop_flower = trmt;
          random block;
  4. Try to add more comments in your program.  This way you will remember what you did in a couple of months.

If I think of any more items, I will come back and add them at a later date.  If you have any suggestions, please drop me a line and I’ll add them in.