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 (May 2003)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 22 May 2003 14:04:15 -0400
Reply-To:   Richard Ristow <wrristow@mindspring.com>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   Richard Ristow <wrristow@mindspring.com>
Subject:   Re: Adding 1 to Numeric Value
Comments:   To: First Last <my_ls_account@yahoo.com>
In-Reply-To:   <20030522162102.41933.qmail@web20501.mail.yahoo.com>
Content-Type:   text/plain; charset="us-ascii"; format=flowed

At 09:21 AM 5/22/2003 -0700, First Last wrote:

>The following sample contains ID (SORTED by ID) and SEQ variables. I >would like to fill in (for only blank/missing SEQ values) by adding +1 >to the maximum >value in the SEQ variable. I would like the resultant data to look like: > >AA 1255555 >BA 1255556 >CA 1255557 >DA 1255558 (previous MAX+1) >EA 1255559 (previous MAX+1) >FA 1255560 (previous MAX+1)

The hardest case is if the blank SEQ values can occur anywhere in the file, and in any order. Then, you need an AGGREGATE to get the previous maximum value. As usual, I assume scratch files may be written freely to c:\TEMP.

COMPUTE NOBREAK=1. AGGREGATE/OUTFILE='c:\TEMP\MAX_SEQ.SAV' /BREAK=NOBREAK /MAXSEQ 'Highest previous sequence no.'= MAX(SEQ).

/* Get the maximum value into the working file; initialize counter */

MATCH FILES /FILE=* /FILE='c:\TEMP\MAX_SEQ.SAV' /BY NOBREAK\FIRST=START_IT.

NUMERIC #NEW_SEQ(F7). /* Scratch variable, retained between cases */ IF (START_IT = 1) #NEW_SEQ = MAXSEQ.

/* Add 1 to maximum and save it, if sequence number is missing */ DO IF (MISSING(SEQ)). . COMPUTE #NEW_SEQ = #NEW_SEQ + 1. . COMPUTE SEQ = #NEW_SEQ. END IF.

MATCH FILES/FILE=*/DROP=NOBREAK MAXSEQ START_IT.

If you know that all the missing sequence numbers are at the end of the file, there are solutions that don't require AGGREGATE.


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