Here's another one for the archives; this time, the user who didn't tell what they really wanted. You contributed to this thread. Here's the post that started it: >Date: Wed, 14 Dec 2005 13:15:57 -0500 >Reply-To: Vivek Kurup >Subject: Reading Numeric Data >To: SPSSX-L@LISTSERV.UGA.EDU >X-ELNK-AV: 0 > >I want to read numeric data from an ASCII file, without dropping the >leading zeros. For ex, 09 shud be read in as 09 and not 9. So, we responded to that, as we interpreted it -- Two posts: how to use N format to display a number with leading zeroes, specifying the width explicitly: >Date: Wed, 14 Dec 2005 20:16:15 +0100 >From: Georg Maubach >Subject: AW: Reading Numeric Data > >as far as I know you could use the FORMATS command by specifying for >example > >(tested code) >FORMATS variable (N3) . /* if you have a numeric field which shall >contain 3 digits */ . >You can change the leading numbers by adjusting Nx. >Date: Wed, 14 Dec 2005 11:21:56 -0800 >From: King Douglas >Subject: Re: Reading Numeric Data >To: SPSSX-L@LISTSERV.UGA.EDU > > Read your numeric data in a usual. Set the format to the desired > number of places as follows: > > FORMATS MyNumVar (N2.0). > In the case above, a value of 9 would appear as 09. > > FORMATS MyNumVar (N4.0) > In the case above, a value of 17 would appear as 0017 Richard, stressing precision, states that what was originally asked is impossible, while not investigating carefully what was really wanted: >Date: Wed, 14 Dec 2005 14:49:08 -0500 >From: Richard Ristow >Subject: Re: Reading Numeric Data >To: SPSSX-L@LISTSERV.UGA.EDU > >At 01:15 PM 12/14/2005, Vivek Kurup wrote: > >>I want to read numeric data from an ASCII file, without dropping the >>leading zeros. > >You've had good advice: use the N format to display your values. > >Remember, though, that this is about display. You can't "read numeric >data from an ASCII file, without dropping the leading zeroes," because >the internal form of numeric values cannot accommodate leading zeroes, >or any similar concept. And now, the original poster comes back with what he REALLY wanted: >Date: Wed, 14 Dec 2005 15:00:40 -0500 >From: Vivek Kurup >Subject: Re: Reading Numeric Data >To: SPSSX-L@LISTSERV.UGA.EDU > >I want to write out double-width data to a text file (onto specified >locations), from a SPSS file which has single-width data. Hence I >wanted to know if I could reformat the current vars to accommodate the >leading 0's. (It's not clear what he means by "double-width" and "single-width". Two digits vs. one digit?) So you can zero in on solving it: >Date: Wed, 14 Dec 2005 12:48:57 -0800 >Reply-To: King Douglas >Subject: Re: Reading Numeric Data >To: SPSSX-L@LISTSERV.UGA.EDU > > Ah! Well, then, you have to create a string variable before writing > to the text file. Say you have a numeric variable MyNumVar of > maximam two places. Before writing out the file, do something like > this: > > STRING MyStrVar(A2). > COMPUTE MyStrVar= LPAD(LTRIM(STRING(MyNumVar,F2),' '),2,'0'). > > Then write the computed string variable, which preserves leading > zeros in the second place: > > WRITE OUTFILE = 'c:\temp\MyStrVar.txt > /1 MyStrVar 1-2 (A). And Richard Oliver of SPSS, Inc. offers a solution using the WRITE command's facilities: >Date: Wed, 14 Dec 2005 15:03:26 -0600 >Reply-To: "Oliver, Richard" >Subject: Re: Reading Numeric Data >To: SPSSX-L@LISTSERV.UGA.EDU > >If you're using the WRITE command to write out the data, you can >include format specifications in the command: >[If the values of var1, var2 and var3 are 1,2 and 3,] > >write outfile='c:\temp\temp.txt' > /var1 (n3) var2 (n3) var3 (n3). >execute. > >In this example, the end result is: >001002003 > >If you're just adding zeroes to get the numbers in a fixed position, >however, this is probably more what you want: > >write outfile='c:\temp\temp.txt' > /var1 (f3) var2 (f3) var3(f3). >execute. > >which results in: > 1 2 3 And that PROBABLY solved it. But it would have been a lot quicker if the poster had been clear in the first place. -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.1.375 / Virus Database: 267.14.23/243 - Release Date: 1/27/2006