Adding leading zeros to a string variable
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.
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)
Translate this page: