I am asking for help understanding what goes wrong when I try to
recode string variables.
I am experiencing a problem recoding variables using syntax window. I
wrote a syntax command trying to recode a variable that has over a
hundred string values (variable 'degreetitle') into a variable that
will have only four values (variable 'degree'). Spss gives me this
warning:
Warning # 208 in column 93. Text: )
>A text string is not correctly enclosed in quotation marks on the command
>line. Literals may not be continued across command lines without the use
>of the continuation symbol '+'.
I tried (unsuccessfully)
(1) making lines shorter
(2) breaking up the command and running step by step
This is only a part of my syntax command :
RECODE
degreetitle
('ASSOC IN ARTS & SCIENCES'='AA') ('ASSOC IN TECHNOLOGY -
GENERAL'='AS')
('ASSOC IN ARTS &SCIENCES'='AA') ('ASSOC IN TECHNOLOGY -
GENERAL'='AS')
('ASSOC. IN APPLIED SCIENCE'='AS') ('ASSOCIATE'S'='AA') ('ASSOCIATE
IN APPLIED SCI'='AS')
('ASSOCIATE IN ARTS'='AA') ('ASSOCIATE IN ARTS DEGREE'='AA')
('ASSOCIATE IN GENERAL STUDIES'='AA') ('ASSOCIATE IN OCC
STUDIES'='AA')
('ASSOCIATE IN SCIENCE'='AS') ('ASSOCIATE OF APPLIED SCIENCE'='AS')
('ASSOCIATE OF ARTS'='AA') ('ASSOCIATE OF ARTS DEGREE'='AA')
('ASSOCIATE OF GENERAL STUDIES'='AA') ('ASSOCIATE OF SCIENCE'='AS')
('ASSOCIATES IN SCIENCE'='AS') ('BS IN BUSINESS & ECONOMICS'='BS')
('B.A.'='BA')
('B.A., HONORS PROGRAM'='BA') ('B.S. , BUSINESS ADMINISTRATION'='BS')
('B.S. IN ACCOUNTANCY'='BS') ('B.S. IN BUSINESS'='BS') ('B.S. IN
BUSINESS ADMIN.'='BS')
('B.S. IN COMPUTER ENGINEERING'='BS') ('B. S. IN ELECTRICAL
ENGINEERING'='BS')
('B.S. IN FOREIGN SERVICE'='BS') ('B.S. IN HEALTH INFORMATIONAL
MANAGEMENT'='BS')
('B.S. IN MECHANICAL ENGINEERING'='BS') ('B.S. IN PLANNING'='BS')
('B.S., BIOLOGY'='BS') ('B.S., BUSINESS ADMINISTRATION'='BS')
('B.S., CHEMISTRY'='BS') ('B.S., MATHEMATICS'='BS') ('B.S.,
NURSING'='BS')
('BACHELOR OF ENVIRONMENTAL DESIGN'='BS') ('BACHELOR OF FINE
ARTS'='BFA') into degree .
EXECUTE .
Thanks to you all!
Here is a problem--the string within the quotes must be all on one
line. Rewrite your RECODE as follows:
RECODE degreetitle
('ASSOC IN ARTS & SCIENCES'='AA')
('ASSOC IN TECHNOLOGY - GENERAL'='AS')
etc
For each value of "degreetitle", make sure the string enclosed in
quotes appears on only one line.
--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."
A possible workaround would be try something like this.
autorecode variables = degreetitle /into ndegree /print.
string degree (a6).
*do these next two procedures until you are happy with the crosstab.
recode ndegree
(1 thru 9='AA')
(11 thru 20, 25, 31 thru 34, 44='BA')
(... = 'BS')
( ... = 'BFA)
(...)
(...)
(else = 'zzoops') into degree.
crostabs tables = degreetitle by degree.
* read the crosstab to see how well you did at specifying the recode go
back and respecify .
Art Kendall
Social Research Consultants
I did what you suggested but the error was still coming up. However,
the new layout helped me find that one of my target variable values
had an apostrophe in it, so when I tried to recode
('Associate's'='AA') spss was reading it as if it is a mistake. After
I fixed the value manually (it had a very low frequency), I was able
to recode the variable without any problems.
I really appreciate your help!
> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/
When the strings can contain apostrophes, use double quotes.
("Associate's"="AA") should work just fine, for example. Note that
you'll need double quotes throughout the RECODE command, not just for
the items that contain apostrophes.
--
Bruce Weaver
bwe...@lakeheadu.ca
> When the strings can contain apostrophes, use double quotes.
> ("Associate's"="AA") should work just fine, for example. Note that
> you'll need double quotes throughout the RECODE command, not just for
> the items that contain apostrophes.
I don't think that the last point is correct. As far as I know
there is no need for consistency, e.g. ("Associate's"='AA')
should work just as well as ("Associate's"="AA").
--
"I don't want to learn the constitution and the declaration of
independence (marvelous poetry though it be) by heart, and worship the
flag and believe that there is a god and the dollar is its prophet."
--Maarten Wiltink in the Monastery
Ben is right. This worked just fine (in v16):
data list list / degreetitle (a35).
begin data
"ASSOC IN ARTS & SCIENCES"
"Associate's"
end data.
string degree (a2).
recode degreetitle
('ASSOC IN ARTS & SCIENCES' = "AA")
("Associate's" = 'AA' ) into degree.
list degree degreetitle.
>Bruce Weaver <bwe...@lakeheadu.ca> writes:
>
>> When the strings can contain apostrophes, use double quotes.
>> ("Associate's"="AA") should work just fine, for example. Note that
>> you'll need double quotes throughout the RECODE command, not just for
>> the items that contain apostrophes.
>
>I don't think that the last point is correct. As far as I know
>there is no need for consistency, e.g. ("Associate's"='AA')
>should work just as well as ("Associate's"="AA").
Doesn't the o ld Fortran convention still work, using two
single quotes in the position of the apostrophe?
('Associate''s' = 'AA') .
--
Rich Ulrich
Should work; it is documented to work.
(I always thought of this as the Pascal convention, for what it's
worth, but I'd guess that Fortran preceded it.)
--
Ben Pfaff
http://benpfaff.org
By twenty years or so.
Interior matching quotes can indeed be doubled if switching the
exterior quote type isn't sufficient. That would only be necessary if
the text being quoted contains both types of quotes.
-Jon Peck