As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Indentation

From sasCommunity
Revision as of 12:00, 10 November 2017 by Paulkaefer (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

When indenting code you should indent the termination character (or command) the same number of spaces as the original command. Unlike other languages that use {} or other methods for specifying sub-blocks of code it matters in SAS that you end the nested block with the proper termination. When the termination is at the same indentation as the initial command then when scanning the code you not only see the end of the original statement but can also confirm that it is ending with the proper termination.

This rule can be applied consistently to PROC and DATA steps, nested groups of statements or to a single statement that spans multiple lines. This snippet shows how to indent a macro %IF .. %DO block of statements, a PROC SQL step, a DATA step and a CREATE statement.

%if %length(&byvar) %then %do; 
*----------------------------------------------------------------------; 
* Make sure all treatment groups are defined for all by groups ; 
*----------------------------------------------------------------------; 
  proc sql; 
    create table n_all as 
      select *,0 as n,0 as nsubj 
      from (select distinct &byvar from subjects) 
         , (select distinct trtvar, trtlabel from subjects) 
      order by &byvar, trtvar, trtlabel 
    ; 
  quit; 
  data nsubj2; 
    merge n_all nsubj2; 
    by &byvar trtvar trtlabel; 
  run; 
%end;

See also