Recoding string to numeric value results in dots

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

carrie_83
Posts: 16
Joined: Fri Nov 18, 2011 2:05 pm

Recoding string to numeric value results in dots

Postby carrie_83 » Tue Nov 22, 2011 10:34 am

Hi,
hoping you could help me with some problems I'm having with syntax command Recode.
This is my code: RECODE Var1 ('RVV'=1) INTO Var1z.
EXECUTE.

The value RVV is one amongst ~50 in that variable, but I only want to use that particular one (to select cases, but since SPSS can't do that if the variable is string, I have to recode it).

Anyways, it runs the command, but the result is just dots, for all values in that variable. What am I doing wrong?
oken
Posts: 9
Joined: Thu Nov 10, 2011 7:26 am

Re: Recoding string to numeric value results in dots

Postby oken » Tue Nov 22, 2011 12:34 pm

I think you should just use the automatic recode dialog box from the Transform menu. You could also recode into same variable or different variables.

Just choose the Var1 as the only variable list.
carrie_83
Posts: 16
Joined: Fri Nov 18, 2011 2:05 pm

Re: Recoding string to numeric value results in dots

Postby carrie_83 » Tue Nov 22, 2011 1:20 pm

I can't use the Transform menu, since the variable is a string variable and it won't recognize the string value in that variable. That's why I have to recode it into a numeric value first.
JonPedersen
Posts: 119
Joined: Wed May 25, 2011 7:07 am
Contact:

Re: Recoding string to numeric value results in dots

Postby JonPedersen » Tue Nov 22, 2011 1:36 pm

Hi,
The code should work as you have written it. But a problem may be blanks at the end or (less likely) beginning of the string. In that case you would have to take them into account by entering them explicitly (e.g. 'RVV ').
Alternative code would be simply:
if VAR1='RVV' var1z=1.
it is not necessary to use select.
To be sure about padded blanks you could use
if char.substr(var1,1,3)='RVV' var1z=1.

hth
jon
carrie_83
Posts: 16
Joined: Fri Nov 18, 2011 2:05 pm

Re: Recoding string to numeric value results in dots

Postby carrie_83 » Tue Jan 03, 2012 2:14 pm

Thank you, that actually worked.

To my next problem with Syntax. I am a semi-experienced user of SPSS, but have so far managed to avoid the Syntax window. Not anymore. Since I haven't worked on syntax code before, I need a little (or maybe a lot of) help.

My problem is this: I have responses from a survey that nobody thought to make "analyzable", hence my problems. I have a variable which includes 11 different age groups. I want to recode these into values ranging from 0 to 11. My code is:
RECODE Q21 (convert) ('Under 20'=0) ('20-24'=1) ('25-29'=2) ('30-34'=3) ('35-39'=4) ('40-44'=5) ('45-49'=6) ('50-54'=7) ('55-59'=8) ('60-64'=9) ('65-69'=10) ('Over 69'=11)
INTO agegroup.
EXECUTE.

When I do this it just gives me values of .00 on each and every one of the groups. What am I doing wrong?? I have checked for blanks and everything, it still gives me the value of .00.
Someone, please help me!
JonPedersen
Posts: 119
Joined: Wed May 25, 2011 7:07 am
Contact:

Re: Recoding string to numeric value results in dots

Postby JonPedersen » Tue Jan 17, 2012 8:31 am

Hi,
It will work if you delete (convert), since convert will act first and convert everything to a number, and your recoding will not be executed.
jon
Analyst Techy
Moderator
Posts: 22
Joined: Mon Apr 27, 2009 2:19 am
Location: Melbourne, Australia

Re: Recoding string to numeric value results in dots

Postby Analyst Techy » Tue Jan 17, 2012 11:51 pm

/* Hi Folks.

/* The syntax below should work

STRING Q21CLEAN (A8).

COMPUTE Q21CLEAN=lower(LTRIM(RTRIM(Q21))).
EXECUTE.

/* DO NOT USE the CONVERT, SPSS gets confused with multiple number values in the one cell eg 30-34
/* MAKE SURE RECODE has all lower case string text

RECODE Q21CLEAN ('under 20'=0) ('20-24'=1) ('25-29'=2) ('30-34'=3) ('35-39'=4) ('40-44'=5) ('45-49'=6) ('50-54'=7) ('55-59'=8) ('60-64'=9) ('65-69'=10) ('over 69'=11)
INTO agegroup.
EXECUTE.
Analyst Techy

NOTES:
Any solutions I provide on this forum are free of charge, donations go towards the maintenance of the unaffiliated SPSS forum.

Who is online

Users browsing this forum: No registered users and 2 guests

cron