Skip to content
Prev 171902 / 398503 Next

Inefficiency of SAS Programming

Barry Rowlingson wrote:
Presumably, something like

      IF &N. =  1 THEN SUB_N = 1;
      ELSE IF &N. < 5 THEN SUB_N = &N.-1;
      ELSE IF &N. < 16 THEN SUB_N = &N.-2;
      ELSE SUB_N = &N.-3;

would work, provided that 2, 5, 16 are impossible values. Problem is 
that it actually makes the code harder to grasp, so experienced SAS 
programmers go for the dumb but readable code like the above.

In R, the cleanest I can think of is

subn <- match(n, setdiff(1:19, c(2,5,16)))

or maybe just

subn <- match(n, c(1, 3:4, 6:15, 17:19))

although

subn <- factor(n, levels = c(1, 3:4, 6:15, 17:19))

might be what is really wanted