Recoding issue

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

Recoding issue

sadeq
Hi there,
I have following data:

    DID  
  --------
   abc
   abc
   abd
   abz
   abz
   abdz
   agdz
How can I recode all values that start with "a" and finish with "z" in RECODE command?

RECODE DID ('a*z'=1)???

Thanks for your help.
Reply | Threaded
Open this post in threaded view
|

Re: Recoding issue

Bruce Weaver
Administrator
You need to study the STRING FUNCTIONS in the UNIVERSALS section of the Command Syntax Reference Manual (aka., the FM).  Here are a couple of them that may be particularly helpful to you:

  CHAR.SUBSTR
  CHAR.LENGTH

Good luck!  ;-)



sadeq wrote
Hi there,
I have following data:

    DID  
  --------
   abc
   abc
   abd
   abz
   abz
   abdz
   agdz
How can I recode all values that start with "a" and finish with "z" in RECODE command?

RECODE DID ('a*z'=1)???

Thanks for your help.
--
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: Recoding issue

David Marso
Administrator
Also CHAR.INDEX and CHAR.RINDEX may be useful.
Luck is for wabbits.

Bruce Weaver wrote
You need to study the STRING FUNCTIONS in the UNIVERSALS section of the Command Syntax Reference Manual (aka., the FM).  Here are a couple of them that may be particularly helpful to you:

  CHAR.SUBSTR
  CHAR.LENGTH

Good luck!  ;-)



sadeq wrote
Hi there,
I have following data:

    DID  
  --------
   abc
   abc
   abd
   abz
   abz
   abdz
   agdz
How can I recode all values that start with "a" and finish with "z" in RECODE command?

RECODE DID ('a*z'=1)???

Thanks for your help.
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: Recoding issue

sadeq
Thanks gents, very helpful.
Reply | Threaded
Open this post in threaded view
|

Re: Recoding issue

David Marso
Administrator
sadeq wrote
Thanks gents, very helpful.
Two different solutions.
DATA LIST / did (A4).
BEGIN DATA
abc
abc
abd
abz
abz
abdz
agdz
END DATA.
COMPUTE a_z= CHAR.INDEX(did,'a') EQ 1 AND CHAR.RINDEX(did,'z')EQ CHAR.LENGTH(did).
COMPUTE a_z2=CHAR.SUBSTR(did,1,1) EQ 'a' AND CHAR.SUBSTR(did,CHAR.LENGTH(did),1) EQ 'z'.
LIST.
 
did       a_z     a_z2
 
abc       .00      .00
abc       .00      .00
abd       .00      .00
abz      1.00     1.00
abz      1.00     1.00
abdz     1.00     1.00
agdz     1.00     1.00
 
 
Number of cases read:  7    Number of cases listed:  7
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?"