3
votes

I am trying to create a new variable that is the sum of other variables. Should be simple enough, however if one of the variables that is being used in the calculation of the new variable has a missing value, then the new variable has a missing value as well, when I want it to just sum across the remaining non-missing variables. For example, the data may look like:

a b c d e
1 . 3 2 6

The new variable is calculated as

newvar=a+b+c+d+e

For the above row, SAS returns a missing value for newvar because b is missing, when I would like it to return

newvar=a+c+d+e

as the answer. Is there a simple way to get SAS to do this?

1

1 Answers

5
votes

Sure thing: just use the SUM function:

data _null_;
  a=1;
  b=.;
  c=3;
  d=2;
  e=6;
  newvar = sum(a,b,c,d,e);
  put newvar=;
run;