```Date: Fri, 12 Mar 2010 22:41:22 -0500 Reply-To: Arthur Tabachneck Sender: "SAS(r) Discussion" From: Arthur Tabachneck Subject: Re: Sum across variables when there are missing values Comments: To: Neil Fernando Neil, I'm glad to hear that Muthia's solution did what you needed, but I don't see any reason why you would include score in the calculation. i.e., I think the following does what you want and should run slightly quicker: DATA food2; SET food1; score = sum(item1, item2, item3); RUN; HTH, Art --------- On Fri, 12 Mar 2010 18:49:39 -0800, Neil Fernando wrote: >Hi Muthia, This is great!?It worked correctly. Now I can apply for my bigger data set. Thanks again! Neil ? Neil Fernando E-mail : neilfrnnd@yahoo.com ________________________________ From: Muthia Kachirayan To: SAS-L@LISTSERV.UGA.EDU Sent: Fri, March 12, 2010 10:00:51 PM Subject: Re: Sum across variables when there are missing values Use SUM() function instead. score = sum(score, item1, item2, item3); On Fri, Mar 12, 2010 at 9:42 PM, Neil Fernando wrote: > Dear Colleagues, > > I have a query as to how the sum of item 1, item2 and item3 could be > obtained across rows when there are missing values > (in SAS). > > data food1; > input item1 item2 item3; > cards; > 0 . 1 > . . 1 > 0 0 . > 1 . 1 > ; > run; > > > DATA food2; >? SET food1; >? ? score = item1 + item2 + item3; > > RUN; > > > My query: I created a new variable named 'score' in food2 dataset. But it > does not give the sum of item1, item2 and item3, instead it gives a period > (.) because of missing values. > > I would appreciate if you could let me know how to get the sum across rows. > > Thank you for your time. > > > Neil Fernando > > E-mail : neilfrnnd@yahoo.com > ```

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