error in syntax - converting string bp into two numeric variables

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

error in syntax - converting string bp into two numeric variables

msherman

Dear List: I am using a sample syntax from SPSSTOOLS before I run it on my data but the sample creates an error message.  Possible solutions ?  thanks, 

DATA LIST FIXED /nb 1-10 (A).

BEGIN DATA

120/90

1425/1

1/2

/3

23/

END DATA.

LIST.

 

* locate the position of the "/".

COMPUTE #pos=INDEX(nb,"/").

 

* Convert the 2 sub-strings into 2 numbers.

COMPUTE nb1=NUMBER(SUBSTR(nb,1,#pos-1),F8.0).

COMPUTE nb2=NUMBER(SUBSTR(nb,#pos+1),F8.0).

EXECUTE.

 

COMPUTE #pos=INDEX(nb,"/").

EXECUTE.

COMPUTE nb1=NUMBER(SUBSTR(nb,1,#pos-1),F8.0).

 

Error # 4285 in column 32.  Text: #pos

Incorrect variable name: either the name is more than 64 characters, or it is

not defined by a previous command.

Execution of this command stops.

 

 

 

Martin F. Sherman, Ph.D.

Professor of Psychology

Director of  Masters Education in Psychology: Thesis Track

Loyola University Maryland

 

Reply | Threaded
Open this post in threaded view
|

Re: error in syntax - converting string bp into two numeric variables

Rick Oliver-3
Remove the EXECUTE statements. Scratch variables (variable names that begin with #) are cleared when a command that reads the data is encountered -- and EXECUTE reads the data.



From:        Martin Sherman <[hidden email]>
To:        [hidden email]
Date:        06/27/2011 02:14 PM
Subject:        error in syntax - converting string bp into two numeric variables
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Dear List: I am using a sample syntax from SPSSTOOLS before I run it on my data but the sample creates an error message.  Possible solutions ?  thanks,  
DATA LIST FIXED /nb 1-10 (A).
BEGIN DATA
120/90
1425/1
1/2
/3
23/
END DATA.
LIST.
 
* locate the position of the "/".
COMPUTE #pos=INDEX(nb,"/").
 
* Convert the 2 sub-strings into 2 numbers.
COMPUTE nb1=NUMBER(SUBSTR(nb,1,#pos-1),F8.0).
COMPUTE nb2=NUMBER(SUBSTR(nb,#pos+1),F8.0).
EXECUTE.
 
COMPUTE #pos=INDEX(nb,"/").
EXECUTE.
COMPUTE nb1=NUMBER(SUBSTR(nb,1,#pos-1),F8.0).
 
Error # 4285 in column 32.  Text: #pos
Incorrect variable name: either the name is more than 64 characters, or it is
not defined by a previous command.
Execution of this command stops.
 
 
 
Martin F. Sherman, Ph.D.
Professor of Psychology
Director of  Masters Education in Psychology: Thesis Track
Loyola University Maryland
 
Reply | Threaded
Open this post in threaded view
|

Re: error in syntax - converting string bp into two numeric variables

Robert Walker
In reply to this post by msherman

Alternatively…

 

COMPUTE nb1=NUMBER(SUBSTR(nb,1,INDEX(nb,"/")-1),F8.0).

COMPUTE nb2=NUMBER(SUBSTR(nb,INDEX(nb,"/")+1),F8.0).

 

Regards,

 

Bob Walker

Surveys & Forecasts, LLC

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Martin Sherman
Sent: Monday, June 27, 2011 3:11 PM
To: [hidden email]
Subject: error in syntax - converting string bp into two numeric variables

 

Dear List: I am using a sample syntax from SPSSTOOLS before I run it on my data but the sample creates an error message.  Possible solutions ?  thanks, 

DATA LIST FIXED /nb 1-10 (A).

BEGIN DATA

120/90

1425/1

1/2

/3

23/

END DATA.

LIST.

 

* locate the position of the "/".

COMPUTE #pos=INDEX(nb,"/").

 

* Convert the 2 sub-strings into 2 numbers.

COMPUTE nb1=NUMBER(SUBSTR(nb,1,#pos-1),F8.0).

COMPUTE nb2=NUMBER(SUBSTR(nb,#pos+1),F8.0).

EXECUTE.

 

COMPUTE #pos=INDEX(nb,"/").

EXECUTE.

COMPUTE nb1=NUMBER(SUBSTR(nb,1,#pos-1),F8.0).

 

Error # 4285 in column 32.  Text: #pos

Incorrect variable name: either the name is more than 64 characters, or it is

not defined by a previous command.

Execution of this command stops.

 

 

 

Martin F. Sherman, Ph.D.

Professor of Psychology

Director of  Masters Education in Psychology: Thesis Track

Loyola University Maryland