New variable testing strings in old variable

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

New variable testing strings in old variable

Tom

Hi

 

Thanks for taking your time and any hint!

 

My problem (SPSS 26):

 

I got a thousands of cases with a string variable like ‘19.343.563.10’ (which stands for a code), most of theme like that, some with an additional letter at the end.

 

My aim: A new variable, which contains a sequential number, for all cases with the identical string the same.

 

I guess, that has to be a syntax (COMPUTE…, or RECODE in a new variable?) using some IF’s and runs through all the cases, but sorry, my knowledge of SPSS isn’t good enough.

 

Regards

Tom

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

Re: New variable testing strings in old variable

bdates
Thomas,

It's always a good idea to include what you would like the final result to be. Can you post what you'd like the result for your example to look like? When a code has a letter at the end, do you want the letter removed so the result can be numerical? An example of the before and after in cases with letters would also be helpful.

Thanks.

Brian

From: SPSSX(r) Discussion <[hidden email]> on behalf of Balmer, Thomas <[hidden email]>
Sent: Thursday, October 24, 2019 11:11 AM
To: [hidden email] <[hidden email]>
Subject: New variable testing strings in old variable
 

Hi

 

Thanks for taking your time and any hint!

 

My problem (SPSS 26):

 

I got a thousands of cases with a string variable like ‘19.343.563.10’ (which stands for a code), most of theme like that, some with an additional letter at the end.

 

My aim: A new variable, which contains a sequential number, for all cases with the identical string the same.

 

I guess, that has to be a syntax (COMPUTE…, or RECODE in a new variable?) using some IF’s and runs through all the cases, but sorry, my knowledge of SPSS isn’t good enough.

 

Regards

Tom

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

Re: New variable testing strings in old variable

Rich Ulrich
In reply to this post by Tom
As I read it, what you want is what you would get with a simple
RANK var= XXX /into=YYY /ties= CONDENSE.
 - if RANK could be used with String variables.
(If I had SPSS here, I would test it because it is so simple, even the
the on-line manual doesn't hint that it might work.)

To get the same thing if RANK doesn't have this as a hidden feature,
you might sort and set up a counter --  something like,
SORT by the var;
DO IF the first case, set IDSEQ to 1 ;
ELSE 
COMPUTE IDSEQ= lag(IDSEQ).           ;
IF (XXX ne lag(XXX) IDSEQ= IDSEQ+1.    ;

Is that what you need?

--
Rich Ulrich


From: SPSSX(r) Discussion <[hidden email]> on behalf of Balmer, Thomas <[hidden email]>
Sent: Thursday, October 24, 2019 11:11 AM
To: [hidden email] <[hidden email]>
Subject: New variable testing strings in old variable
 

Hi

 

Thanks for taking your time and any hint!

 

My problem (SPSS 26):

 

I got a thousands of cases with a string variable like ‘19.343.563.10’ (which stands for a code), most of theme like that, some with an additional letter at the end.

 

My aim: A new variable, which contains a sequential number, for all cases with the identical string the same.

 

I guess, that has to be a syntax (COMPUTE…, or RECODE in a new variable?) using some IF’s and runs through all the cases, but sorry, my knowledge of SPSS isn’t good enough.

 

Regards

Tom

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

Re: New variable testing strings in old variable

spss.giesel@yahoo.de
In reply to this post by Tom
Hi, Tom,

you can use AUTORECODE for this.

Mario Giesel
Munich, Germany


Am Donnerstag, 24. Oktober 2019, 17:11:51 MESZ hat Balmer, Thomas <[hidden email]> Folgendes geschrieben:


Hi

 

Thanks for taking your time and any hint!

 

My problem (SPSS 26):

 

I got a thousands of cases with a string variable like ‘19.343.563.10’ (which stands for a code), most of theme like that, some with an additional letter at the end.

 

My aim: A new variable, which contains a sequential number, for all cases with the identical string the same.

 

I guess, that has to be a syntax (COMPUTE…, or RECODE in a new variable?) using some IF’s and runs through all the cases, but sorry, my knowledge of SPSS isn’t good enough.

 

Regards

Tom

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

Re: New variable testing strings in old variable

Bruce Weaver
Administrator
RANK (suggested by Rich) was a good idea, but unfortunately, RANK does not
work with string variables (as I discovered when I tried it).  Mario's
AUTORECODE looks like the most efficient approach.


DATA LIST LIST / stringvar (A15).
BEGIN DATA
"19.343.563.09"
"19.343.563.10"
"19.343.563.10"
"19.343.563.11"
"19.343.563.10"
"19.343.563.10"
"19.343.563.11"
"19.343.563.12"
"19.343.563.10"
"19.343.563.12"
"19.343.563.12"
"19.343.564.10"
END DATA.

RANK VARIABLES=stringvar (A)
  /RANK
  /PRINT=YES
  /TIES=CONDENSE.
* NOTE:  This RANK command generates the following warning:
* Text: stringvar Command: RANK
* A string variable was used in a variable list where only numeric variables
are allowed.
* Execution of this command stops.
* No analysis is performed because of an invalid input variable list.

* Compute a variable to store the original order of the cases in case it is
needed later.
COMPUTE case = $casenum.
FORMATS case(F5.0).
VARIABLE LABELS case "Original order in file".
DESCRIPTIVES case.

* Sort by the string variable, then generate the SeqNo variable.
SORT CASES BY stringvar.
* Use a DM trick to compute new variable SeqNo.
COMPUTE SeqNo = SUM(LAG(SeqNo),stringvar NE LAG(stringvar)).
FORMATS SeqNo (F5.0).
LIST.
SORT CASES by case. /* Restore original order if desired.
LIST.

* Now using AUTORECODE, as suggested by Mario.

AUTORECODE VARIABLES=stringvar  /INTO SeqNo2.
LIST.

* AUTORECODE looks like the winner.



[hidden email] wrote
> Hi, Tom,
> you can use AUTORECODE for this.
> Mario GieselMunich, Germany
>
>     Am Donnerstag, 24. Oktober 2019, 17:11:51 MESZ hat Balmer, Thomas &lt;

> Thomas.Balmer@

> &gt; Folgendes geschrieben:  
>  
> Hi
>  
> Thanks for taking your time and any hint!
>  
> My problem (SPSS 26):
>  
> I got a thousands of cases with a string variable like ‘19.343.563.10’
> (which stands for a code), most of theme like that, some with an
> additional letter at the end.
>  
> My aim: A new variable, which contains a sequential number, for all cases
> with the identical string the same.
>  
> I guess, that has to be a syntax (COMPUTE…, or RECODE in a new variable?)
> using some IF’s and runs through all the cases, but sorry, my knowledge of
> SPSS isn’t good enough.
>  
> Regards
>  
> Tom





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Tom
Reply | Threaded
Open this post in threaded view
|

AW: New variable testing strings in old variable

Tom
In reply to this post by spss.giesel@yahoo.de

Hi Mario

 

That works perfect, thank you.

 

Tom

 

Von: Mario Giesel <[hidden email]>
Gesendet: Donnerstag, 24. Oktober 2019 20:25
An: [hidden email]; Balmer, Thomas <[hidden email]>
Betreff: Re: New variable testing strings in old variable

 

Hi, Tom,

 

you can use AUTORECODE for this.

 

Mario Giesel

Munich, Germany

 

 

Am Donnerstag, 24. Oktober 2019, 17:11:51 MESZ hat Balmer, Thomas <[hidden email]> Folgendes geschrieben:

 

 

Hi

 

Thanks for taking your time and any hint!

 

My problem (SPSS 26):

 

I got a thousands of cases with a string variable like ‘19.343.563.10’ (which stands for a code), most of theme like that, some with an additional letter at the end.

 

My aim: A new variable, which contains a sequential number, for all cases with the identical string the same.

 

I guess, that has to be a syntax (COMPUTE…, or RECODE in a new variable?) using some IF’s and runs through all the cases, but sorry, my knowledge of SPSS isn’t good enough.

 

Regards

Tom

===================== 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

===================== 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