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 (January 2008)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 7 Jan 2008 19:41:12 -0700
Reply-To:     ViAnn Beadle <vab88011@gmail.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         ViAnn Beadle <vab88011@gmail.com>
Subject:      FW: Adding Leading Zeros To An ID
Content-Type: text/plain; charset="us-ascii"

It turns out that left or right justification need not matter for the string id. So, if the oldid is a string variable, this set of syntax will declare a new string variable, and then compute the new string number from the existing string:

STRING newid(A6). COMPUTE newid=STRING(NUMBER(oldid,F6.0),N6).

This somewhat convoluted COMPUTE creates an intermediate numeric value using the NUMBER function as input to the STRING function. The NUMBER function reads the string value as a number with a standard F format (to handle leading or trailing blanks). The STRING function then converts that number to a string using the N format to create a display representation to convert. ---Original Message----- From: ViAnn Beadle [mailto:vab88011@gmail.com] Sent: Monday, January 07, 2008 6:43 PM To: 'SPSSX-L@LISTSERV.UGA.EDU' Subject: RE: Adding Leading Zeros To An ID

The reply assumes that the ID variable is a number. Is it a string or a number? If it is a string, is it displayed left-justified or right-justified within the data editor? That will determine how to modify the string value.

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Oliver, Richard Sent: Monday, January 07, 2008 6:14 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: Adding Leading Zeros To An ID

formats ID (n6).

________________________________

From: SPSSX(r) Discussion on behalf of Don Asay Sent: Mon 1/7/2008 5:54 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Adding Leading Zeros To An ID

I have an ID variable that should be 6 charachters long some ranging from 000001 to 999999. Some of the records lost their leading zeros so instead of having 000015 the computer stored 15, this is not the case for all of the IDs with leading zeros some are stored properly as 000023 and the very next one wil be 24 without the leading zeros. I want to create syntax to add the leading zeros, but I can't figure out how to conditionally prepend the zeros to just the cases that don't already have them. Any help would be appreciated.

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

======= To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD


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