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 (October 2009, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 28 Oct 2009 10:31:49 -0500
Reply-To:     Joe Matise <snoopy369@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Joe Matise <snoopy369@GMAIL.COM>
Subject:      Re: Is there a function to count the number of distinct
              non-missing values in an array?
Comments: To: Jack Clark <jclark@hilltop.umbc.edu>
In-Reply-To:  <b7a7fa630910280819j3543762ate8994151535a20b7@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Still not caffeinated, I missed the 'distinct' bit. Bah.

Someone replied in a new thread (or at least gmail displays it that way) suggesting concatenating them into a string; that might work, certainly, something like do _n_ = 1 to 50; if find(newstring,array[_n_]) = 0 then newstring=catx("|",newstring,array[_n_]); end; then count the |'s (plus one).

Also, you might be able to use CALL SORTC. Assuming you care about the x1-x50 being kept in place, put them into a temporary array, call sortc them, and then do a normal comparison routine going up the line.

do _n_ = 1 to 50; if savedvar ne array[_n_] then do; count=count+1; savedvar=array[_n_]; end; end;

-Joe

On Wed, Oct 28, 2009 at 10:19 AM, Joe Matise <snoopy369@gmail.com> wrote:

> NMISS() will count the number of missing, then subtract? > > data test; > array x x1-x50; > do _t = 1 to 20; > do _n_ = 1 to 50; > call missing(x[_n_]); > if ranuni(7) < .5 then x[_n_] = 1; > end; > n_valid = 50-nmiss(of x:); > output; > end; > run; > > > -Joe > > > On Wed, Oct 28, 2009 at 7:50 AM, Jack Clark <jclark@hilltop.umbc.edu>wrote: > >> Good morning, >> >> >> >> I have a data set with character variables like var1-var50. Not all >> records have values in all 50 variables. For each record, I would like >> to know the number of distinct, non-missing values across the 50 >> variables. My ultimate goal is to have a frequency report of this count >> so I know that x number of obs. in the data set have 1 unique value, y >> number of obs. in the data set have 2 unique values, etc. >> >> >> >> I have thought of switching from my short and wide data set structure to >> a tall and long one (with transpose or data step), then that may make >> counting distinct values easier (maybe with PROC SQL). But I was >> wondering if anyone knows of some clever data step method or array >> function (?) that would work. >> >> >> >> Thanks in advance. >> >> >> >> >> Jack >> >> >> >> Jack Clark >> Senior Research Analyst >> phone: 410-455-6256 >> fax: 410-455-6850 >> jclark@hilltop.umbc.edu >> >> University of Maryland, Baltimore County >> Sondheim Hall, 3rd Floor >> 1000 Hilltop Circle >> Baltimore, MD 21250 >> >> >> >> >> Confidentiality Notice: This e-mail may contain information that is >> legally privileged and that is intended only for the use of the addressee(s) >> named above. If you are not the intended recipient, you are hereby notified >> that any disclosure, copying of this e-mail, distribution, or action taken >> in reliance on the contents of this e-mail and/or documents attributed to >> this e-mail is strictly prohibited. If you have received this information in >> error, please notify the sender immediately by phone and delete this entire >> e-mail. Thank you. >> > >


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