LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2000, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 3 Mar 2000 17:47:25 -0800
Reply-To:     Andrew James Llwellyn Cary <ajlcary@CARYCONSULTING.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Andrew James Llwellyn Cary <ajlcary@CARYCONSULTING.COM>
Subject:      Re: deleting records where all numeric variables = 0

One Solution uses a trick in SAS: a logical operator can be mixed with arithmetic operators to build a count of non-zero values.

ARRAY _NumVars_ [] _NUMERIC_ ;

NNonZero=0;

DO __i =1 to DIM(_NumVars); NNonZero = NNonZero + (_NumVars[__i] ~= 0 ); END;

IF NNonZero = 0 THEN DELETE;

DROP __i NNonZero;

This method treats missing values as non-zero.

Another way uses the max and min functions...

IF MAX(OF -NUMERIC-) = 0 AND MIN(OF _NUMERIC_) = 0 THEN DELETE;

This method ignores missing values (effectively treating them as zero).

Caveat: none of this code was tested- there may be typos...

-- Andrew James Llwellyn Cary Sr. Curmudgeon Cary Consulting Services http://www.CaryConsulting.Com

"Nick Treadgold" <Nick_Treadgold@STATS.GOVT.NZ> wrote in message news:4C256897.000C4EF6.00@mail.stats.govt.nz... > I would like to condense a dataset by deleting all records where all > numeric variables = 0. > > this is one option.... > > if var1=0 and var2=0 and var3=0 then delete ; > > but i'm sure there is a simpler and more obvious solution. > > Note: > this is not a suitable option for me.... > > if sum(of var1-var3)=0 then delete; > > > Nick Treadgold > Economic Statistician > Statistics New Zealand > Phone: (03) 374 8834 > Fax: 03 374-8899 > Email: nick_treadgold@stats.govt.nz > Home Page: http://www.stats.govt.nz > The information in this email, and any files transmitted with it, is > confidential and is for the intended recipient only. If you receive this > message in error, please phone us (collect) on 04-495-4600, or notify us > via postmaster@stats.govt.nz


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