sponsor Vim development Vim logo Vim Book Ad

SAS Indent : Indent Script for SAS 9.1/9.2/9.3/9.4

 script karma  Rating 57/20, Downloaded by 3470  Comments, bugs, improvements  Vim wiki

created by
Zhenhuan Hu
script type
Indent script for SAS. The algorithm is supposed to be rather tolerable.

Examples of the indenting results are shown as following:

1. For data step/proc sections, the script can properly indent with or without the closing run/quit statements.
   (SAS does not require explicit closing statements for data step/proc sections.)

   data female;
      set total; where gender = 0;
   data male;
      set total; where gender = 1;
   proc sort data = new; by gender;
   proc freq data = new;
      table gender / missing;

2. The script can also recognize which procedure supports run-processing and indent accordingly.

   proc reg;
      model y = x1-x5;
      model y = x1-x10;

3. The indentation is properly managed when mixed with macros.
   (Nesting macro is evil. Don't do it)

   %macro test();
      data new;
         set old; where age >= 18;
         format gender gender.;
      proc freq;
         table gender;

4. Logic expressions.

   data a;
      set b; where age >= 18;
      if numtx = 1 and not (pid > 0 and dcitag in (1, 2)) then strata = 3;
      else if pid > 0 then do;
         if dcitag in (1, 2) then do;
            strata = 1; dcitype = 1;
         else if dcipsh1 = 1 then do;
            strata = 1; dcitype = 3;
         else if numtx > 1 then strata = 2;
      else do;
         if dcitag2 in (1, 2) then do; strata = 1; dcitype = 2; end;
         else if dcipsh1 = 1 then do; strata = 1; dcitype = 3; end;
         else if pid < 0 and dcipsh1 ~= 1 and numtx > 1 then strata = 2;

Please also check out my SAS syntax script: http://vim.sourceforge.net/scripts/script.php?script_id=3522
install details

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
sas.vim 3.0.1 2017-03-13 7.0 Zhenhuan Hu Fix an issue in indenting macro %end.
sas.vim 3.0.0 2017-03-10 7.0 Zhenhuan Hu Support proper indentation for run-processing procedures.
sas.vim 2.2 2016-08-09 7.0 Zhenhuan Hu Change the behavior how ENDSAS is indented. Now it indents at the same level as the first non-blank line of the program instead of no indent.
sas.vim 2.1 2016-08-08 7.0 Zhenhuan Hu Fix an issue when no indent is made at the end of a macro
sas.vim 2.0 2012-05-09 7.0 Zhenhuan Hu Implemented a brand new algorithm for indenting. Now indenting will be correct with or without close data/proc section by run statement. Added enddata keyword.
sas.vim 1.1 2012-04-30 7.0 Zhenhuan Hu Optimized the indenting approach. Added keyword QUIT.
sas.vim 1.0 2012-04-26 7.0 Zhenhuan Hu Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
Vim at Github