Skip to content
AgileLogics
4 min read

Comments and Style

Prerequisites: PROC PRINT and PROC SORT

Comments

/* A block comment.
   It can span several lines. */

* A statement comment ends at the next semicolon;

data work.clean;              /* comments can follow code */
   set sashelp.class;
   bmi = 703 * weight / height**2;
run;
  • /* ... */ works anywhere, even inside a statement. It's the safer choice, and SAS Studio toggles it with Ctrl + /.
  • * ... ; is a statement, so it must end with a semicolon — and it can't contain one.

Start each program with a header comment: purpose, author, date, inputs, and outputs. In regulated work (clinical trials, banking) this is often required.

Style guidelines

SAS doesn't enforce any layout, but readable programs share habits:

  • One statement per line, and indent the statements inside a step (three or four spaces).
  • End every step with run; (or quit;) — don't rely on the next DATA or PROC to end it.
  • Lowercase code is the modern convention; some teams use uppercase keywords. Pick one and be consistent.
  • Meaningful names: visit_date, not vd. Use underscores.
  • Blank lines between steps, and a comment above each step saying why it exists.
  • Name output data sets explicitly (data work.adults;) instead of relying on defaults.
  • Declare lengths for new character variables.
  • Keep the log clean — no errors, no warnings, and no unexpected notes such as "missing values were generated" or "character values have been converted". A clean log is how SAS programmers prove a program works.

A tidy program

/*------------------------------------------------------------
  Program : class_summary.sas
  Purpose : List students over 60 inches with BMI
  Input   : SASHELP.CLASS
  Output  : WORK.TALL_BMI
------------------------------------------------------------*/

data work.tall_bmi;
   set sashelp.class;
   where height > 60;
   bmi = round(703 * weight / height**2, 0.1);
   keep name sex height weight bmi;
run;

proc sort data=work.tall_bmi;
   by descending bmi;
run;

proc print data=work.tall_bmi noobs;
run;

What's next

You now know the core of SAS. Try the Beginner Projects, then continue to Level 2 — Intermediate, which starts with importing real data files.