Flag cases where a strong variable contains only the EXACT word

classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Flag cases where a strong variable contains only the EXACT word

David Marso
Administrator


On Fri, Jun 9, 2017 at 12:24 PM, David Marso [via SPSSX Discussion] <[hidden email]> wrote:
COMPUTE #copy = CONCAT("!",LTRIM(UPCASE(F_EMPNAME)),"!").
might be better as:
COMPUTE #copy = CONCAT("!",LTRIM(RTRIM(UPCASE(F_EMPNAME))),"!").
It wouldn't matter if you were running in UNICODE mode.

Mike Paul wrote

Hi Bruce, many thanks, I deleted the EXECUTE, but when running the list the cases do not get flagged...  not sure if you have any thoughts on what could be going wrong?

Here's my syntax/output:

STRING #copy (A50).
COMPUTE #copy = CONCAT("!",LTRIM(UPCASE(F_EMPNAME)),"!").
COMPUTE Flag_T100 = SUM(
 CHAR.INDEX(#copy, "!APPLE!"),
 CHAR.INDEX(#copy, "!TESCO!"),
 CHAR.INDEX(#copy, "!FACEBOOK!")) GT 0.
FORMATS Flag_T100(F1).
LIST Flag_T100 F_EMPNAME.

Flag_T100  F_EMPNAME

    0    Aberdeen City Council
    0    University of Leeds
    0    Facebook
    0    Unknown

Etc. .................. ***not copied all the list!****

Number of cases read:  424,373    Number of cases listed:  424,373

TEMPORARY.
SELECT IF Flag_T100.
LIST Flag_T100 F_EMPNAME.

List

Number of cases read:  0    Number of cases listed:  0
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?"



To unsubscribe from Flag cases where a strong variable contains only the EXACT word, click here.
NAML

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?"
Reply | Threaded
Open this post in threaded view
|

Re: Flag cases where a strong variable contains only the EXACT word

Bruce Weaver
Administrator
In reply to this post by David Marso
Good call, David--assuming you meant RTRIM where you typed UTRIM.  ;-)

COMPUTE #copy = CONCAT("!",LTRIM(RTRIM(UPCASE(F_EMPNAME))),"!").

I am running in UNICODE mode, which is why I did not bother with that.

And Mike, when using a file with several thousand cases, I would get rid of the LIST commands.  All that output is not useful.  Try something like this instead:

TEMPORARY.
SELECT IF Flag_T100.
FREQUENCIES F_EMPNAME.

HTH.


David Marso wrote
COMPUTE #copy = CONCAT("!",LTRIM(UPCASE(F_EMPNAME)),"!").
might be better as:
COMPUTE #copy = CONCAT("!",LTRIM(UTRIM(UPCASE(F_EMPNAME))),"!").
It wouldn't matter if you were running in UNICODE mode.

Mike Paul wrote

Hi Bruce, many thanks, I deleted the EXECUTE, but when running the list the cases do not get flagged...  not sure if you have any thoughts on what could be going wrong?

Here's my syntax/output:

STRING #copy (A50).
COMPUTE #copy = CONCAT("!",LTRIM(UPCASE(F_EMPNAME)),"!").
COMPUTE Flag_T100 = SUM(
 CHAR.INDEX(#copy, "!APPLE!"),
 CHAR.INDEX(#copy, "!TESCO!"),
 CHAR.INDEX(#copy, "!FACEBOOK!")) GT 0.
FORMATS Flag_T100(F1).
LIST Flag_T100 F_EMPNAME.

Flag_T100  F_EMPNAME

    0    Aberdeen City Council
    0    University of Leeds
    0    Facebook
    0    Unknown

Etc. .................. ***not copied all the list!****

Number of cases read:  424,373    Number of cases listed:  424,373

TEMPORARY.
SELECT IF Flag_T100.
LIST Flag_T100 F_EMPNAME.

List

Number of cases read:  0    Number of cases listed:  0
--
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/).
Reply | Threaded
Open this post in threaded view
|

Re: Flag cases where a strong variable contains only the EXACT word

Art Kendall
In reply to this post by David Marso
The autorecode and eyball approach would also be simplified a little by cleaning the input string into a new variable UPCASE, and removing leading blanks.
e.

 this is example syntax for the "AUTORECODE and eyeball to draft RECODE approach".

This probably could be generalized by using TEMPLATE within AUTORECODE.

Note how the 3 and 5 come out in the new set of values.

data list list /F_EmpName (a30).
begin data
'apple'
'APPLES'
'Aple'
'Apple'
'APPLE'
'Applecroft School'
'Appletree Court'
'Apple'
'Apple'
'Apple'
'Apple Blossom Lodge'
'Apple Blosom Lodge'
'The Apples Medical Centre NHS'
end data.
dataset name mydata.
autorecode F_EmpName /into F_EmpName# /print.

RECODE  F_EmpName# (1,2,3,4=3)(5,6=5)(ELSE=COPY) into clean_F_EmpName#.
formats clean_F_EmpName# (f2).
APPLY DICTIONARY from mydata /source variables = F_EmpName# /target variables= clean_F_EmpName#.
execute.
string clean_EmpName (a30).
compute clean_EmpName = valuelabel(clean_F_EmpName#).
sort cases by clean_F_EmpName# F_EmpName#.
list.
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Flag cases where a strong variable contains only the EXACT word

Mike Paul
In reply to this post by Bruce Weaver
Many thanks Bruce and David - it worked for me!

Also going to try the look-up table too... thanks everybody for the great advice.
12