Adding leading zeros to a string variable

Technote (troubleshooting)


Problem(Abstract)

I would like to add leading zeros to my variable in SPSS. Is there an easy way to do this if my variable is a string?

Resolving the problem

If your variable is in string format, you will first need to convert it into a numeric variable using one of the following two pieces of syntax:

RECODE var (CONVERT) INTO numvar.
exe.

or

COMPUTE numvar=NUMBER(var,f8).
exe.

Once you have done this, you can use the format 'N' to give it a restricted format. Just specify a format that you would like to use. The following syntax will give the specified variable an eight character format. If the value has fewer than eight digits, it will have leading zeros:

FORMATS numvar (n8)

Historical Number

14871

Rate this page:

(0 users)Average rating

Add comments

Document information


More support for:

SPSS Statistics

Software version:

Not Applicable

Operating system(s):

MAC, Windows

Reference #:

1476073

Modified date:

2010-04-26

Translate my page

Machine Translation

Content navigation