|
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:[hidden email]] Sent: Monday, January 07, 2008 6:43 PM To: '[hidden email]' 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:[hidden email]] On Behalf Of Oliver, Richard Sent: Monday, January 07, 2008 6:14 PM To: [hidden email] 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: [hidden email] 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 [hidden email] (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 [hidden email] (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 [hidden email] (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 |
| Free forum by Nabble | Edit this page |
