The value begins with...

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

Beuzza
Posts: 4
Joined: Thu Feb 27, 2014 11:52 am

The value begins with...

Postby Beuzza » Thu Feb 27, 2014 12:04 pm

Hi everybody! I'm new in this forum and I am new in the use of SPSS.

The version I'm using is the 19.
My data are alphanumeric codes: 7 digits - Letter + Number+Number+Letter+Letter+Number+Number.
What I would like to do is the extraction of those data that begin with a partial code (e.g. C03).

For the complete value I have solved the issue by computing a new variable defined by the function ANY, but I can't find a solution for the retrieving of the cases by looking for a partial code. Actually I do not know how to tell SPSS that "C03" is only the initial part of the value it will find in the cells.

Could you please help me?

Thank you in advance!
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: The value begins with...

Postby GerineL » Thu Feb 27, 2014 1:08 pm

create a new variable with substring that only exists of first 3 characters.
does that help?
Beuzza
Posts: 4
Joined: Thu Feb 27, 2014 11:52 am

Re: The value begins with...

Postby Beuzza » Tue Apr 08, 2014 11:05 am

Hi Gutnre,

thank you for your answer! I'm trying to do what you suggested me.
The codes I want to extract are in the variable @1B.
So, I'm creating a new variable using the function CHAR.SUBSTR.
Assuming that I want the new variable to show only the first of seven characters present in the colomn @1B, I have completed the function as follows:

NewVariable = CHAR.SUBSTR(@1B,1,1)

But it doesn't work. I think I have misinterpreted the way the function should be completed. Could you please help me understanding where I am wrong??

Thank you in advance.

B.
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: The value begins with...

Postby GerineL » Tue Apr 08, 2014 11:47 am

try this:

string newvar (a8).
execute.

compute newvar = substr(oldvar,1,7).
execute.



first, create the variable.
then, compute it and go from the first character until the seventh character.
Beuzza
Posts: 4
Joined: Thu Feb 27, 2014 11:52 am

Re: The value begins with...

Postby Beuzza » Tue Apr 08, 2014 1:08 pm

Gutnre wrote:try this:

string newvar (a8).
execute.

compute newvar = substr(oldvar,1,7).
execute.



first, create the variable.
then, compute it and go from the first character until the seventh character.
I've tried it but an Error occured:

Error # 4309 in column 1024. Text: (End of Command)
Invalid combination of data types in an assignment. Character strings may
only be assigned to string variables. Numeric and logical quantities may
only be assigned to numeric variables. Consider using the STRING or NUMBER
function.
Execution of this command stops.



To solve this I thought that I should have "declared" the variable @1B as string. So I wrote this:

string @1B (a8).
execute.

string @1BILiv (a8).
execute.

compute @1BILiv = substr(@1B,1,7).
execute.

But the Output reported me the error #4822 in colomn 8 which regards the fact that (rightfully) the variable @1B already exists...

How can I solve it?
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: The value begins with...

Postby GerineL » Tue Apr 08, 2014 1:47 pm

is the original variable a string already?
if so, you can just leave that part out (spss knows it is a string).

with the string...(a8) thing you create new variables, so you cannot give it a name that already exists.
Beuzza
Posts: 4
Joined: Thu Feb 27, 2014 11:52 am

Re: The value begins with...

Postby Beuzza » Tue Apr 08, 2014 2:41 pm

I've closed all the windows and then recreated a new syntax file and... the magic happened!! :D I'm so happy!

Thank you very much!! Really!

B.

Who is online

Users browsing this forum: No registered users and 2 guests

cron