Date: Wed, 20 Jul 2011 13:29:37 -0700
Reply-To: David Marso <david.marso@gmail.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: David Marso <david.marso@gmail.com>
Subject: Re: Count of unique values across variables
In-Reply-To: <000f01cc46fa$6734bea0$359e3be0$@co.uk>
Content-Type: text/plain; charset=us-ascii
Easier to simply aggregate twice after the V2C. Or just use the LOOP code
posted previously.
VARSTOCASES
/MAKE zip FROM zip2006 zip2007 zip2008 zip2009 zip2010 zip2011
/KEEP=id
/NULL=DROP.
AGGREGATE OUTFILE * / BREAK id zip / N=N.
AGGREGATE OUTFILE * / BREAK ID / unique=N.
Garry Gelade wrote:
>
> Nancy
>
> Try this.
>
> DATA LIST LIST / id , zip2006, zip2007, zip2008, zip2009, zip2010,
> zip2011.
> BEGIN DATA
> 1, 61477,
> 2, 61477, 41365,
> 3, 41365, 41365, 41365, 41365, 41365, 41365
> END DATA.
> FORMATS id zip2006 to zip2011 (F5.0).
>
>
> VARSTOCASES
> /MAKE zip FROM zip2006 zip2007 zip2008 zip2009 zip2010 zip2011
> /KEEP=id
> /NULL=DROP.
>
> SORT CASES BY id(A) zip(A).
> MATCH FILES /FILE=* /BY id zip /FIRST=PrimaryFirst
> /LAST=PrimaryLast.
> DO IF (PrimaryFirst).
> COMPUTE MatchSequence=1-PrimaryLast.
> ELSE.
> COMPUTE MatchSequence=MatchSequence+1.
> END IF.
> LEAVE MatchSequence.
> FORMATS MatchSequence (f7).
> COMPUTE InDupGrp=MatchSequence>0.
> SORT CASES InDupGrp(D).
> MATCH FILES /FILE=* /DROP=PrimaryFirst InDupGrp MatchSequence.
>
> SELECT IF (PrimaryLast=1).
> EXECUTE.
>
> DATASET DECLARE Counts.
> AGGREGATE /OUTFILE='Counts' /BREAK=id /N_UNIQUE=N.
> DATASET ACTIVATE Counts.
> LIST.
>
> You end up with the following dataset Counts, which you can merge with
> your
> origninal file if you want.
> ===================================================.
> id N_UNIQUE
>
> 1 1
> 2 2
> 3 1
>
>
> Regards
>
> Garry Gelade
>
>
>
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of
> Nancy Rusinak
> Sent: 20 July 2011 03:27
> To: SPSSX-L@LISTSERV.UGA.EDU
> Subject: Count of unique values across variables
>
> Hello!
>
> I'm trying to find a way to get a count of unique values across 6
> variables:
>
> zip 2006 zip2007 zip2008 zip2009 zip2010 zip2011
> 61477
> 61477 41365
> 41365 41365 41365 41365 41365 41365
>
> In the data above, I'd like to add a variable called "count." for the
> first
> case, the value of count would be "1" as there is only 1 unique zip in all
> 6
> columns. For the second case, "count" would equal "2" and for the third
> case, count would equal "1"
>
> I'm new to syntax and would appreciate any handholding you could offer
> with
> accomplishing this.
>
> My heartfelt thanks if you can help!
>
> Nancy
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Count-of-unique-values-across-variables-tp4614377p4617197.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.
=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
|