```Date: Mon, 20 Aug 2007 12:45:25 -0700 Reply-To: "Terjeson, Mark" Sender: "SAS(r) Discussion" From: "Terjeson, Mark" Subject: Re: Subtracting 2 variables Comments: To: tanwan In-Reply-To: A<1187638376.158603.13580@m37g2000prh.googlegroups.com> Content-Type: text/plain; charset="us-ascii" Hi Tanwan, I am going to avoid calling your new variable as the right_diff because subtracting number 9 from number 0 is indeed -9, however subtracting 9 from 'nothing' is not necessarily -9. In your case if that is what you want then what you are doing is desiring to have any missings converted from nothing to zero and then perform your arithmetic. For that specific purpose only you can code it like this: data test; input a b; wrong_sum = a+b; right_sum=sum(a, b); wrong_diff=a-b; your_diff=max(a,0)-max(b,0); cards; 1 2 . 9 7 . ; run; -or- data test; input a b; wrong_sum = a+b; right_sum=sum(a, b); wrong_diff=a-b; your_diff=sum(a,0)-sum(b,0); cards; 1 2 . 9 7 . ; run; -or- data test; input a b; wrong_sum = a+b; right_sum=sum(a, b); wrong_diff=a-b; your_diff=sum(a,-b,0); cards; 1 2 . 9 7 . ; run; Hope this is helpful. Mark Terjeson Senior Programmer Analyst, IM&R Russell Investments Russell Investments Global Leaders in Multi-Manager Investing -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of tanwan Sent: Monday, August 20, 2007 12:33 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Subtracting 2 variables When adding, using '+' may produce wrong results (if some obs are missing), so one may use the SUM function. Is there a fuction equivalent to SUM for subtracting, that can handle missing data? As in: data; input a b; wrong_sum = a+b; right_sum=sum(a, b); wrong_diff=a-b; cards; 1 2 . 9 7 . ;proc print; run; I would like to have the right_diff as -1, -9 and 7 ```

Back to: Top of message | Previous page | Main SAS-L page