[R] Inefficiency of SAS Programming

Frank E Harrell Jr f.harrell at vanderbilt.edu
Fri Feb 27 16:41:27 CET 2009


Terry Therneau wrote:
> Three comments
> 
>  I actually think you can write worse code in R than in SAS: more tools = more 
> scope for innovatively bad ideas.  The ability to write bad code should not damm 
> a language.  
>  
>   I found almost all of the "improvements" to the multi-line SAS recode to be 
> regressions, both the SAS and the S suggestions. 
>     a. Everyone, even those of you with no SAS backround whatsoever, immediately 
> understood the code.  Most of the replacements are obscure.  Compilers are very 
> good these days and computers are fast, fewer typed characters != better.
>     b. If I were writing the S code for such an application, it would look much 
> the same.  I worked as a programmer in medical research for several years, and 
> one of the things that moved me on to graduate studies in statistics was the 
> realization that doing my best work meant being as UN-clever as possible in my 
> code.  

If I were writing S code for this it would be dramatically different.  I 
would try to be efficient and elegant but would need to remember to be a 
teacher at the same time.  For example this kind of recode is super 
efficient and quick to program but would need good comments or a 
handbook to all of my code:  c(cat=1, dog=2, giraffe=3)[animal]
But I think the code is quite intuitive once you have used that 
construct once.

There also a lot of factoring of code that could be done as others have 
pointed out.

>     
>   Frank's comments imply that he was reading SAS macro code at the moment of 
> peak frustration.  And if you want to criticise SAS code, this is the place to 
> look.  SAS macro started out as some simple expansions, then got added on to, 
> then added on again, and again, and ....  with no overall blueprint.  It is much 
> like the farmhouse of some neighbors of mine growing up: 4 different expansions 
> in 4 eras, and no overall guiding plan.  The interior layout was "interesting" 
> to say the least. I was once a bona fide SAS 'wizard' (and Frank was much better 
> than me), and I can't read the stuff without grinding my teeth.
>   S was once headed down the same road. One of the best things ever with the 
> language was documented in the blue book "The New S Language", where Becker et 
> al had the wisdom to scrap the macro processor.  

Well put.  I am amazed there hasn't been a revolt among SAS users 
decades ago.  The S approach is also easier to debug one line at a time.

Cheers,
Frank

>  
>   	Terry Therneau
> 
> 


-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University




More information about the R-help mailing list