Dear list!
I know I have seen a solution to this a long time ago but has forgotten how. Can anyone help? best Staffan Lindberg Sweden ===================== 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 |
Assuming the first character is always
a letter:
data list free /alphanum (a10). begin data aBcD1234 end data. compute alphanum=concat(upper(char.substr(alphanum,1,1)), lower(char.substr(alphanum,2))). list. Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: "[hidden email]" <[hidden email]> To: [hidden email], Date: 02/10/2014 09:25 AM Subject: How to transform alpha-numerical values in a variable in lower case letters so that the first letter becomes upper case? Sent by: "SPSSX(r) Discussion" <[hidden email]> Dear list! I know I have seen a solution to this a long time ago but has forgotten how. Can anyone help? best Staffan Lindberg Sweden ===================== 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 |
In reply to this post by Staffan Lindberg
Wait. If you don't care about the case
of the remaining letters, you can omit the LOWER function:
compute alphanum=concat(upper(char.substr(alphanum,1,1)), char.substr(alphanum,2)). Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: Rick Oliver/Chicago/IBM To: "[hidden email]" <[hidden email]>, Cc: [hidden email] Date: 02/10/2014 09:40 AM Subject: Re: How to transform alpha-numerical values in a variable in lower case letters so that the first letter becomes upper case? Assuming the first character is always a letter: data list free /alphanum (a10). begin data aBcD1234 end data. compute alphanum=concat(upper(char.substr(alphanum,1,1)), lower(char.substr(alphanum,2))). list. Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: "[hidden email]" <[hidden email]> To: [hidden email], Date: 02/10/2014 09:25 AM Subject: How to transform alpha-numerical values in a variable in lower case letters so that the first letter becomes upper case? Sent by: "SPSSX(r) Discussion" <[hidden email]> Dear list! I know I have seen a solution to this a long time ago but has forgotten how. Can anyone help? best Staffan Lindberg Sweden ===================== 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 |
Administrator
|
In reply to this post by Staffan Lindberg
One way is with SUBSTR on the left of the equals sign, like this:
DATA LIST list / StringVar(a25). BEGIN DATA "this is all lowercase." "so is this." END DATA. LIST. STRING # (A1). COMPUTE # = CHAR.SUBSTR(StringVar,1,1). COMPUTE substr(StringVar,1,1) = UPPER(#). LIST. Final output: StringVar This is all lowercase. So is this. Number of cases read: 2 Number of cases listed: 2
--
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/). |
As I keep saying, left hand side substr
is a bad idea. In Unicode mode, you can't substitute into a string
this way, because characters are not all the same number of bytes.
Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Bruce Weaver <[hidden email]> To: [hidden email], Date: 02/10/2014 08:51 AM Subject: Re: [SPSSX-L] How to transform alpha-numerical values in a variable in lower case letters so that the first letter becomes upper case? Sent by: "SPSSX(r) Discussion" <[hidden email]> One way is with SUBSTR on the left of the equals sign, like this: DATA LIST list / StringVar(a25). BEGIN DATA "this is all lowercase." "so is this." END DATA. LIST. STRING # (A1). COMPUTE # = CHAR.SUBSTR(StringVar,1,1). COMPUTE substr(StringVar,1,1) = UPPER(#). LIST. Final output: StringVar This is all lowercase. So is this. Number of cases read: 2 Number of cases listed: 2 Staffan Lindberg wrote > Dear list! > > I know I have seen a solution to this a long time ago but has > forgotten how. Can anyone help? > > best > > Staffan Lindberg > Sweden > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (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 ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-transform-alpha-numerical-values-in-a-variable-in-lower-case-letters-so-that-the-first-letter-tp5724418p5724422.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 |
In reply to this post by Staffan Lindberg
Python has a a title case modifier to string objects - useful if you have more complicated strings.
**********************************. DATA LIST FREE / MyStr (A20). BEGIN DATA xxxxx yyyyy AAAbb bABAaa "bb AAA cCC DddD" END DATA. BEGIN PROGRAM. def Title(s): return s.title() END PROGRAM. SPSSINC TRANS RESULT=TitleStr TYPE=20 /FORMULA Title(MyStr). **********************************. I thought maybe you could trick the TRANS function to return the transformed object by just giving it "/FORMULA str(MyStr).title() ." but that did not work. |
Free forum by Nabble | Edit this page |