I have numeric 8.0 variables with value labels
1=Cat 2=Dog.
Is there a way to make new variables that are a string that has the string [like Cat] not the number [1]? Have tried Alter type and Auto-recode unsuccessfully. I want to concat the variables - something like "Dog, Cat" - this being one string variable. Any hints would be great. Regards -- Mark Webb Line +27 (21) 786 4379 Cell +27 (72) 199 1000 [Poor reception] Fax +27 (86) 260 1946 Skype tomarkwebb Email [hidden email]===================== 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
|
Mark,
Look up the VALUELABEL function (used with COMPUTE after allocating a string variable). STRING mylabel (A120). COMPUTE mylabel=VALUELABEL(oldvar). HTH, David --
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?" |
This post was updated on .
In reply to this post by Mark Webb-5
This post might be useful to answer your query?
**************************************. DATA LIST FREE / id (a2) APPLE (f1.0) PEAR(f1.0) BANANA(f1.0) FRUITS (a999). BEGIN DATA 01 1 0 0 "Apple" 02 0 1 1 "Pear" 03 0 0 1 "Banana" 04 1 1 0 "Apple, Pear" 05 1 0 1 "Apple, Banana" 06 0 1 1 "Banana, Pear" 07 1 1 1 "Apple, Pear, Banana" 08 0 0 0 "" END DATA. VALUE LABELS /APPLE 1 'Apple' /PEAR 1 'Pear' /BANANA 1 'Banana'. STRING #s Fruit2 (A100). DO REPEAT o = APPLE PEAR BANANA. COMPUTE #s = VALUELABEL(o). DO IF #s <> "" AND Fruit2 = "". COMPUTE Fruit2 = #s. ELSE IF #s <> "" AND Fruit2 <> "". COMPUTE Fruit2 = CONCAT(RTRIM(Fruit2),", ",#s). END IF. END REPEAT. EXECUTE. **************************************. |
Pasted incorrect link in previous post:
Correct link: http://spssx-discussion.1045642.n5.nabble.com/Collapse-concatenate-multicodes-tp5728482p5728484.html |
In reply to this post by Mark Webb-5
The valuelabel function returns the label
for a value.
Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Mark Webb <[hidden email]> To: [hidden email] Date: 02/09/2015 07:28 AM Subject: [SPSSX-L] How to - Converting value labels to a string variable? Sent by: "SPSSX(r) Discussion" <[hidden email]> I have numeric 8.0 variables with value labels 1=Cat 2=Dog. Is there a way to make new variables that are a string that has the string [like Cat] not the number [1]? Have tried Alter type and Auto-recode unsuccessfully. I want to concat the variables - something like "Dog, Cat" - this being one string variable. Any hints would be great. Regards -- Mark Webb Line +27 (21) 786 4379 Cell +27 (72) 199 1000 [Poor reception] Fax +27 (86) 260 1946 Skype tomarkwebb Email targetlinkmark@... ===================== 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 |