sponsor Vim development Vim logo go to HTTPS page Vim Book Ad

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

 script karma  Rating 18/6, Downloaded by 977    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/proc sections, the script will properly manage indentations with or without the closing of run/quit statements. (SAS does not require explicit closing statements for data/proc sections.)

   data female;
         set total; where gender = 0;
   data male;
         set total; where gender = 1;
   data new;
         set female male;

   proc sort data = new;
         by gender;
   proc freq data = new;
         table gender / missing;

2. Even mixed with macro, the indentation is properly managed.

   %macro temp();
         data new;
               where age >= 18;
               format gender gender.;
         proc freq data = new;
               table gender / missing;
   %mend; * Without closing by run statement;

3. 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;
               else if dcipsh1 = 1 then do;
                     strata = 1; dcitype = 3;
               else if pid < 0 and dcipsh1 ~= 1 and numtx > 1 then strata = 2;

   The script will also recognize complex logic expressions written in one single line and would not change its indentation.

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 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.
SourceForge.net Logo