|
Hello everyone. I'm trying to extract the first character in a string variable representing diagnostic codes (e.g., 536.3 Gastroparesis) because I need to determine the frequency of general codes by their first number (e.g., 5's, 7's, 9's). However, I can't seem to locate any syntax that allows me to do this.
Your help would be much appreciated--thanks! Sincerely, Jill Stoltzfus --------------------------------- Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. ===================== 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 |
|
The SUBSTR() function does this, e.g.,
string generalCode (a1). compute generalCode = substr(code,1,1). From the syntax guide: SUBSTR. SUBSTR(strexpr,pos[,length]). String. Returns the substring beginning at position pos of strexpr and running for length length. If the optional argument length is omitted, returns the substring beginning at position pos of strexpr and running to the end of strexpr. For example SUBSTR(’abcd’, 2) returns ’bcd’ and SUBSTR(’abcd’, 2, 2) returns ’bc’. When used on the left side of an equals sign, the substring is replaced by the string specified on the right side of the equals sign. The rest of the original string remains intact. For example, SUBSTR(ALPHA6,3,1)='*' changes the third character of all values for ALPHA6 to *. If the replacement string is longer or shorter than the substring, the replacement is truncated or padded with blanks on the right to an equal length. Hope this helps, Jill Stoltzfus wrote: > Hello everyone. I'm trying to extract the first character in a string variable representing diagnostic codes (e.g., 536.3 Gastroparesis) because I need to determine the frequency of general codes by their first number (e.g., 5's, 7's, 9's). However, I can't seem to locate any syntax that allows me to do this. > > Your help would be much appreciated--thanks! > > Sincerely, > > Jill Stoltzfus > > > > > > --------------------------------- > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. > > ===================== > 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 > > -- Daniel Robertson Senior Research and Planning Associate Institutional Research and Planning Cornell University / irp.cornell.edu ===================== 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 Jill Stoltzfus
Hi Jill
The standard function is: Compute firstchar = substr(ltrim(diagcode), 1, 1). Provided "firstchar" is a string variable. If the diagnostic codes already start on the position one, you can go the straight way: String firstchar (a1). Compute firstchar = diagcode. (The rest of the string is dropped because the variable firstchar is too short to contain it.) /All code untested, but I believe that it will be correct at least in principle./ Jan -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jill Stoltzfus Sent: Wednesday, April 30, 2008 4:36 PM To: [hidden email] Subject: Extracting first character in a string variable Hello everyone. I'm trying to extract the first character in a string variable representing diagnostic codes (e.g., 536.3 Gastroparesis) because I need to determine the frequency of general codes by their first number (e.g., 5's, 7's, 9's). However, I can't seem to locate any syntax that allows me to do this. Your help would be much appreciated--thanks! Sincerely, Jill Stoltzfus --------------------------------- Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. ===================== 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 _____________ Tato zpráva a všechny připojené soubory jsou důvěrné a určené výlučně adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno jakékoliv zveřejňování, zprostředkování nebo jiné použití těchto informací. Jestliže jste tento mail dostali neoprávněně, prosím, uvědomte odesilatele a smažte zprávu i přiložené soubory. Odesilatel nezodpovídá za jakékoliv chyby nebo opomenutí způsobené tímto přenosem. Jste si jisti, že opravdu potřebujete vytisknout tuto zprávu a/nebo její přílohy? Myslete na přírodu. This message and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact the sender and delete the message as well as all attached documents. The sender does not accept liability for any errors or omissions as a result of the transmission. Are you sure that you really need a print version of this message and/or its attachments? Think about nature. -.- -- ===================== 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 |
