format a variable?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

format a variable?

Samuel Solomon
Hi list,

 

Is there a way how to keep leading zeros throughout an operation?
Moreover I need a format say 1,000,000. etc. is it possible in spss?

 

Regards,

 

Samuel.

 
Reply | Threaded
Open this post in threaded view
|

Re: format a variable?

Ken Chui
Yes for both.

To keep leading zero, you may use FORMATS var (N___) syntax.  Please refer
to this thread:
http://listserv.uga.edu/cgi-bin/wa?A2=ind9708&L=spssx-l&D=0&P=1634

To show comma, you may use FORMATS var (COMMAxxx.yyy), where xxx is the
number digit before decimal place, and yyy is the number behind.  So, for
your case 1,000,000, it'd be (COMMA7.0).  You may also do that in variable
view under the column type, click and change it to "comma".

Hope this helps,

-Ken

>Hi list,
>
>
>
>Is there a way how to keep leading zeros throughout an operation?
>Moreover I need a format say 1,000,000. etc. is it possible in spss?
>
>
>
>Regards,
>
>
>
>Samuel.
>
>
Reply | Threaded
Open this post in threaded view
|

Re: format a variable?

Samuel Solomon
In reply to this post by Samuel Solomon
That does it! Thanks indeed. I never new the format type 'N' exists
other than 'F'. I am still novice, but I am swallowing a lot!

Regards,
Samuel

-----Original Message-----
From: Ken Chui [mailto:[hidden email]]
Sent: Wednesday, August 30, 2006 5:42 PM
To: [hidden email]; Samuel Solomon
Subject: Re: format a variable?

Yes for both.

To keep leading zero, you may use FORMATS var (N___) syntax.  Please
refer
to this thread:
http://listserv.uga.edu/cgi-bin/wa?A2=ind9708&L=spssx-l&D=0&P=1634

To show comma, you may use FORMATS var (COMMAxxx.yyy), where xxx is the
number digit before decimal place, and yyy is the number behind.  So,
for
your case 1,000,000, it'd be (COMMA7.0).  You may also do that in
variable
view under the column type, click and change it to "comma".

Hope this helps,

-Ken

>Hi list,
>
>
>
>Is there a way how to keep leading zeros throughout an operation?
>Moreover I need a format say 1,000,000. etc. is it possible in spss?
>
>
>
>Regards,
>
>
>
>Samuel.
>
>
Reply | Threaded
Open this post in threaded view
|

Re: format a variable?

Richard Ristow
In reply to this post by Samuel Solomon
A point that's worth mentioning from time to time -

At 02:41 AM 8/30/2006, Samuel Solomon wrote:

>Is there a way how to keep leading zeros throughout an operation?
>Moreover I need a format say 1,000,000. etc. is it possible in spss?

And the Nww and COMMAw.d formats give the right display.

The point is: you can display any number with leading zeroes; but you
aren't keeping the leading zeroes, through the calculations. SPSS
numbers, as SPSS stores them, are in a binary format that neither had
nor lacks leading zeroes; the leading zeroes (as well as commas) are
not properties of the numbers, but of the particular rules used to
display them.
Reply | Threaded
Open this post in threaded view
|

Re: format a variable?

Dennis Deck
In reply to this post by Samuel Solomon
Ah. haven't used Nww before.

A somewhat different application came up this week - merging two files
with a common 12-digit school ID - except that in one file it was
numeric and in the other a string with leading zeros.  MATCH FILES will,
of course, fail with different data types (or when matching where one
string lacks the padded 0s).  The following code converts the numeric
variable to its string equivalent and pads leading zeros.

STRING SchlCode (A12) .
COMPUTE SchlCode = LPAD(LTRIM(STRING(School,F12.0),' '),12,'0') .

I'll bet this can be simplified to:

STRING SchlCode (A12) .
COMPUTE SchlCode = STRING(School,N12) .


Dennis Deck, PhD
RMC Research Corporation
[hidden email]

-----Original Message-----
From: Richard Ristow [mailto:[hidden email]]
Sent: Thursday, August 31, 2006 8:06 PM
Subject: Re: format a variable?

A point that's worth mentioning from time to time -

At 02:41 AM 8/30/2006, Samuel Solomon wrote:

>Is there a way how to keep leading zeros throughout an operation?
>Moreover I need a format say 1,000,000. etc. is it possible in spss?

And the Nww and COMMAw.d formats give the right display.

The point is: you can display any number with leading zeroes; but you
aren't keeping the leading zeroes, through the calculations. SPSS
numbers, as SPSS stores them, are in a binary format that neither had
nor lacks leading zeroes; the leading zeroes (as well as commas) are
not properties of the numbers, but of the particular rules used to
display them.