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 2005)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 18 Oct 2005 10:13:30 -0400
Reply-To:     kong1 <kong1@umbc.edu>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
Comments:     To: Richard Ristow <wrristow@mindspring.com>
From:         kong1 <kong1@umbc.edu>
Subject:      Re: calculation
In-Reply-To:  <5.1.0.14.2.20051017183544.06c5de50@pop.mindspring.com>
Content-Type: text/plain; charset="us-ascii"

Richard,

Thank you very much! It worked out.

Thanks again.

Benny

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Richard Ristow Sent: Monday, October 17, 2005 7:04 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: calculation

At 04:20 PM 10/17/2005, Benny Kong wrote:

>We have to calculate two new variables based on another variable, for >example, > >rcdlgth start end > (TBC) (TBC) >2 1 2 >4 3 6 >5 7 11 >6 12 17 >... > >RcdLgth is extracted from a data layout file, that is, record length; >and we need to compute the start column and end column so as to >compile a syntax to import the data. To illustrate, the first variable >has a length of 2, then the start column is 1 and end column is 2; the >second variable is 4 in length, then the start column is 3 and ends in >the 6th column; so on and so forth. We see a consistent pattern here; >however, we find it difficulty in computing the two new variables. >Could someone help us out?

I take it that your input file has the fields in order (I hope to goodness, with a sequence number so you can check the order), with no gaps between fields. (Or if there are gaps, they have records with "record lengths" as well.) If so, I think this is what you want. Code is tested; this is SPSS draft output. "TBCSTART" and "TBCEND" are the "to be computed" variables read from your test data. I've generated variable FIELDNUM.

*............................... LIST. |---------------------------|------------------------| |Output Created |17 Oct 05 19:00:16 | |---------------------------|------------------------| FIELDNUM RCDLGTH TBCSTART TBCEND

1 2 1 2 2 4 3 6 3 5 7 11 4 6 12 17

Number of cases read: 4 Number of cases listed: 4

NUMERIC START END (F3). DO IF MISSING(LAG(rcdlgth)). COMPUTE START = 1. ELSE. COMPUTE START = LAG(END)+ 1. END IF. COMPUTE END = START + rcdlgth - 1. LIST. |---------------------------|------------------------| |Output Created |17 Oct 05 19:00:17 | |---------------------------|------------------------| FIELDNUM RCDLGTH TBCSTART TBCEND START END

1 2 1 2 1 2 2 4 3 6 3 6 3 5 7 11 7 11 4 6 12 17 12 17

Number of cases read: 4 Number of cases listed: 4


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