Thursday, May 24, 2012

Enhanced Editor Preferences

Here are some suggested Enhanced Editor settings and related best practices. Select Tools | Options | Enhanced Editor... and enabled Show line numbers, Insert spaces for tabs and Replace spaces with tabs on file open. I also like to set my tab size to 2 spaces (see below).

The other suggested setting is achieved by selecting Tools | Options | Preferences... and setting Recently used file list to the maximum value of 30 entries.

With those settings in place here are some suggested best practices when writing code:

  • One line of code (ends in semicolon) per line making it easier to read and maintain
  • Indent each subservient line with 2 spaces
  • Start each SQL column with a comma so it is self contained and easy to comment out
  • Align columns as appropriate to make it easier to read and maintian


    proc sql noprint stimer ;
      connect to odbc ( "%getconnection( server = Prod )" ) ;
        create table commodity as
          select   *
            from   connection to odbc
              select        commoditycode
                      /*  , commodityabbreviation
                          , commodityname   */
                          , count(*) as count
                from        arm.common.commodity       
                where       commoditycode = '0041'
                group by    commoditycode
                      /*  , commodityabbreviation
                          , commodityname   */
                order by    commoditycode
                      /*  , commodityabbreviation
                          , commodityname   */
            ) ;
      disconnect from odbc ;
    quit ;
Compare and contrast the ease of using leading commas versus a conditional trailing comma in this macro based example:
    %do i=1 %to 10;
      , yr&i._acre_qty as acre&i 
      , yr&i._yield_qty as yield&i
    %do i=1 %to 10;
      %if &i<10 %then %do;
        yr&i._acre_qty as acre&i ,
        yr&i._yield_qty as yield&i ,
      %else %do;
        yr&i._acre_qty as acre&i ,
        yr&i._yield_qty as yield&i 

No comments:

Post a Comment