Compute Variable = .

Reply
Frequent Contributor
Posts: 75

Compute Variable = .

I have

A=.

B = 10

C=5

I want to obtain

D= A + (B*C)

but I get D=.

it should be D=50

how do I overcome this issue?

Thanks

Contributor
Posts: 62

Re: Compute Variable = .

Please use sum and mult functions as '+' operator will give missing values...hope it helped.

Thank You


Occasional Contributor
Posts: 17

Re: Compute Variable = .

D=sum(A, B*C);

or use if-else logic to customize the missing cases. e.g.

if  missing(A)=1 then A1=0; /* not necessarily so */

     else A1=A;

if missing(B)=1 then B1=0; /* not necessarily so */

     else B1=B;

if missing(C)=1 then C1=1; /* not necessarily so */

     else C1=C;

D=A1+B1*C1;

Super Contributor
Posts: 276

Re: Compute Variable = .

How About,,

data _null_;

a=.;

b=5;

c=10;

d=Sum(a,B*c);

Put d;

run;

,

Thanks,

Sanjeev.K

Contributor
Posts: 62

Re: Compute Variable = .

This will work for missing values of A, you cannont have missing values while you are multiplying.. hope answered the question.

Thank You

Respected Advisor
Posts: 2,655

Re: Compute Variable = .

Apple,

There have been many good examples on how to calculate the answer that you want.  I'd like to address this in a different way (that might make sense if you consider only + and * as operators).  With a missing value for A in your example, you say the answer should be 50.  My question is "How do you know"?  A is missing and not necessarily equal to zero.  It might be anything--you just don't have information.  Consequently, any function that includes A as an operand is lacking in information.  SAS thus rightly treats the result as missing.  If you know that A is truly equal to zero when missing, then I would write something like bill0101's if-then-else logic.

Steve Denham

Ask a Question
Discussion stats
  • 5 replies
  • 232 views
  • 1 like
  • 5 in conversation