Dear all,
I have a SPSS file with 5 string variables. These string variables are: V1,F2 = string variable (range 01-20) V2,F4 = string variable (range 2000-2999) V3,F2 = string variable (range 01-25) V4,F2 = string variable (range 01-50) V5,F6 = string variable (range 000000 - 999999) I would like to combine these variables in a way that I can compose one new variable, for example: 19_20030202000999 I have tried to create this new variable in SPSS (V20.), using 'Compute variable' and the CONCAT function for string variables. However, it doesn't work. I have tried: CONCAT(STRING(V1,F2),STRING('_'),STRING(V2,F4),STRING(V3,F2),STRING(V4,F2),STRING(V5,F6)) Can someone help me in creating the right function to develop the new variable? Thanks in advance. |
Administrator
|
Please define "it doesn't work"!!!
Error messages? If these are already string variables then why are you using the STRING function internally. If numeric then why are you describing them as strings? Have you used the STRING function to allocate the resulting variable? PLEASE PASTE THE SYNTAX that is ACTUALLY generated! STRING resultvar (A17). COMPUTE resultvar=CONCAT(v1,v2,v3,v4,v5). FREQ resultvar. ----
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?" |
Administrator
|
In reply to this post by ralingh
It would be helpful to see your actual syntax. When computing a new string variable, you must first initialize it with a STRING command (otherwise SPSS will try to compute a new numeric variable). E.g.,
STRING NewStringVar (A20). COMPUTE NewStringVar = CONCAT(STRING(V1,F2), STRING('_'), STRING(V2,F4), STRING(V3,F2), STRING(V4,F2), STRING(V5,F6)). My guess is you omitted the STRING command. HTH.
--
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/). |
In reply to this post by ralingh
At 07:09 AM 3/12/2014, ralingh wrote:
>I have a SPSS file with 5 string variables. These string variables are: >V1,F2 = string variable (range 01-20) >V2,F4 = string variable (range 2000-2999) >V3,F2 = string variable (range 01-25) >V4,F2 = string variable (range 01-50) >V5,F6 = string variable (range 000000 - 999999) > >I would like to combine these variables in a way that I can compose one new >variable, for example: >19_20030202000999 > >I have tried to create this new variable using 'the CONCAT function >for string variables. However, it doesn't work. I have tried: > >CONCAT(STRING(V1,F2),STRING('_'),STRING(V2,F4),STRING(V3,F2),STRING(V4,F2),STRING(V5,F6)) In addition to Bruce Weaver's reminder that you need to declare the new variable you're creating, the subexpressions like "STRING(V1,F2)" are invalid. If your variables V1 to V5 really are strings, the expression you want is CONCAT(V1,'_',V2,V3,V4,V5) ===================== 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 |
If any of these string field values might
occupy less than the full field width, the results might be ambiguous.
In code page mode, the string values would always have full width, but in Unicode mode, string values are blank trimmed on the right. In that case, the values should be wrapped in the NTRIM function to preserve trailing blanks if the result needs to be unambiguous. For example, CONCAT(NTRIM(V1),'_',NTRIM(V2),NTRIM(V3),NTRIM(V4),NTRIM(V5)) Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Richard Ristow <[hidden email]> To: [hidden email], Date: 03/19/2014 11:22 AM Subject: Re: [SPSSX-L] Concatenate string variables Sent by: "SPSSX(r) Discussion" <[hidden email]> At 07:09 AM 3/12/2014, ralingh wrote: >I have a SPSS file with 5 string variables. These string variables are: >V1,F2 = string variable (range 01-20) >V2,F4 = string variable (range 2000-2999) >V3,F2 = string variable (range 01-25) >V4,F2 = string variable (range 01-50) >V5,F6 = string variable (range 000000 - 999999) > >I would like to combine these variables in a way that I can compose one new >variable, for example: >19_20030202000999 > >I have tried to create this new variable using 'the CONCAT function >for string variables. However, it doesn't work. I have tried: > >CONCAT(STRING(V1,F2),STRING('_'),STRING(V2,F4),STRING(V3,F2),STRING(V4,F2),STRING(V5,F6)) In addition to Bruce Weaver's reminder that you need to declare the new variable you're creating, the subexpressions like "STRING(V1,F2)" are invalid. If your variables V1 to V5 really are strings, the expression you want is CONCAT(V1,'_',V2,V3,V4,V5) ===================== 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 |