have you ever had a syntax that works, then it doesn't? I have a variable that has values that are 3-5 digits. I want them all to be 5 digits, by adding 0 to the end of those that are only 3 or 4 digits long. The syntax worked last year when I had to do this, this year it didn't work at first, but then it did for one variable- I tried to run the next one, and again it didn't work. I can't see where there are any differences in these 2 variables. Can anyone suggest another way to do this? And why would something work one time and then not work another time? Here is the syntax I used.
STRING Diag1 (A5). COMPUTE Diag1 = char.RPAD(ltrim(DiagnosisCode1),5,"0") . EXECUTE . STRING Diag2 (A5). COMPUTE Diag2 = char.RPAD(ltrim(DiagnosisCode2),5,"0") . EXECUTE . STRING Diag3 (A5). COMPUTE Diag3 = char.RPAD(ltrim(DiagnosisCode3),5,"0") . EXECUTE . my data looks like this-- result should be this 29500 29500 311 31100 3004 30040 29750 29750 29750 29750 Thanks in advance for any guidance you can give! |
Administrator
|
You should always post any error messages!
Also, 'doesn't work' is really not very helpful! What do you mean by 'doesn't work'? Meanwhile confirm that each of the original variables are defined as string and NOT numeric. "And why would something work one time and then not work another time?" Answer: Differing context? Something IS DIFFERENT?
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by vstirkey
My best would be that DiagnosisCode needs to be a string for your code to work, and in the new dataset it is now in a numeric variable. Possible solutions are to use ALTER TYPE to change DiagnosisCode to a string variable, or instead of
LTRIM(DiagnosisCode1) use LTRIM(STRING(DiagnosisCode1,F5.0)) To make consistent code though all three of the DiagnosisCode variables need to be in the same string or numeric format. |
In reply to this post by David Marso
Thanks for the response! There is no error message, The resulting variable is exactly the same as the original, like so. 29500 29500 From: David Marso [via SPSSX Discussion] [mailto:[hidden email]] You should always post any error messages! vstirkey wrote have you ever had a syntax that works, then it doesn't? I have a variable that has values that are 3-5 digits. I want them all to be 5 digits, by adding 0 to the end of those that are only 3 or 4 digits long. The syntax worked last year when I had to do this, this year it didn't work at first, but then it did for one variable- I tried to run the next one, and again it didn't work. I can't see where there are any differences in these 2 variables. Can anyone suggest another way to do this? And why would something work one time and then not work another time? Here is the syntax I used. Please reply to the list and not to my personal email. If you reply to this email, your message will be added to the discussion below: To unsubscribe from adding zeroes to a string variable, click here. |
Administrator
|
Re David's other point, what types of variables (i.e., numeric or string) are the input and output variables?
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Both input and output are strings. From: Bruce Weaver [via SPSSX Discussion] [mailto:[hidden email]] Re David's other point, what types of variables (i.e., numeric or string) are the input and output variables? vstirkey wrote Thanks for the response! There is no error message, -- If you reply to this email, your message will be added to the discussion below: To unsubscribe from adding zeroes to a string variable, click here. |
Since the strings appear not to have any
leading blanks, the ltrim does nothing, but if you are not in Unicode mode,
you would need an rtrim. In Unicode mode, trailing blanks are automatically
removed.
Also, might you have nonprinting characters at the end of these strings for some of the variables? You can change the format to AHEX10 to see the numerical codes. A blank should appear as 20 in AHEX. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: vstirkey <[hidden email]> To: [hidden email] Date: 12/24/2014 10:54 AM Subject: Re: [SPSSX-L] adding zeroes to a string variable Sent by: "SPSSX(r) Discussion" <[hidden email]> Both input and output are strings.
From: Bruce Weaver [via SPSSX Discussion]
[mailto:[hidden
email]]
Re David's other point, what types of variables (i.e.,
numeric or string) are the input and output variables? vstirkey wrote Thanks for the response! There is no error message,
If you reply to this email, your message will be added to the discussion below: http://spssx-discussion.1045642.n5.nabble.com/adding-zeroes-to-a-string-variable-tp5728279p5728283.html
View this message in context: RE: adding zeroes to a string variable Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@... (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 |