[R] Inefficiency of SAS Programming

JRG loesljrg at verizon.net
Fri Feb 27 01:25:01 CET 2009


On 26 Feb 2009 at 23:47, Barry Rowlingson wrote:

> 2009/2/26 Frank E Harrell Jr <f.harrell at vanderbilt.edu>:
> > If anyone wants to see a prime example of how inefficient it is to program
> > in SAS, take a look at the SAS programs provided by the US Agency for
> > Healthcare Research and Quality for risk adjusting and reporting for
> > hospital outcomes at http://www.qualityindicators.ahrq.gov/software.htm .
> >  The PSSASP3.SAS program is a prime example.  Look at how you do a vector
> > product in the SAS macro language to evaluate predictions from a logistic
> > regression model.  I estimate that using R would easily cut the programming
> > time of this set of programs by a factor of 4.
> 
>  Plenty of examples ripe for sending to www.thedailywtf.com there. Like this:
> 
>     IF &N. =  1 THEN SUB_N = 1;
>     IF &N. =  3 THEN SUB_N = 2;
>     IF &N. =  4 THEN SUB_N = 3;
>     IF &N. =  6 THEN SUB_N = 4;
>     IF &N. =  7 THEN SUB_N = 5;
>     IF &N. =  8 THEN SUB_N = 6;
>     IF &N. =  9 THEN SUB_N = 7;
>     IF &N. = 10 THEN SUB_N = 8;
>     IF &N. = 11 THEN SUB_N = 9;
>     IF &N. = 12 THEN SUB_N = 10;
>     IF &N. = 13 THEN SUB_N = 11;
>     IF &N. = 14 THEN SUB_N = 12;
>     IF &N. = 15 THEN SUB_N = 13;
>     IF &N. = 17 THEN SUB_N = 14;
>     IF &N. = 18 THEN SUB_N = 15;
>     IF &N. = 19 THEN SUB_N = 16;
> 
> Of course it's possible to write code like that in any language, it
> just looks worse when it's in ALL CAPS and written in a style that
> looks like the 1980s and onward never happened. The question is
> whether it's possible to write this better in SAS. Most of us on this
> list could write it in R in a better way.

Oh, it's definitely possible to write better SAS code than that.  This should do the trick:

   Sub_n = input(scan("1 . 2 3 . 4 5 6 7  8  9 10 11 12 13  . 14 15 16", &N, " "), 2.);

among various other ways.

But it remains true that certain operations in SAS will be quite inefficient.

---JRG

> 
>  Barry
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


John R. Gleason
Associate Professor

Syracuse University
430 Huntington Hall                      Voice:   315-443-3107
Syracuse, NY 13244-2340  USA             FAX:     315-443-4085

PGP public key at keyservers




More information about the R-help mailing list