CHAR.SUBSTR & CHAR.LENGTH

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

helenspain
Posts: 4
Joined: Wed Feb 13, 2013 12:51 pm

CHAR.SUBSTR & CHAR.LENGTH

Postby helenspain » Wed Feb 13, 2013 1:11 pm

Hi there! I've a problem with these functions.
I've a string called A1, and I wanna create a substring (CALLED SA2) from it. The point is that I need to take 3 characters from the string A1, counting from position -5, to create the substring SA2, so I decided to use CHAR.SUBSTR + CHAR.LENGTH.
This is the syntax:

COMPUTE SA2 = CHAR.SUBSTR(A1,CHAR.LENGTH(A1)-5,3).
EXECUTE.

But, it's not working. I've tried a lot of combinations, but nothing.
The fact is the program can't execute the syntax because it's wrong (invalid argument). But I don't know exactly where the mistake is.

Please, I need your help.
Sorry for my english, I'm from Spain. :)
Thanks! :D
apeape
Posts: 56
Joined: Mon May 02, 2011 6:07 pm

Re: CHAR.SUBSTR & CHAR.LENGTH

Postby apeape » Wed Feb 13, 2013 3:05 pm

You should paste the error verbatim - it's more helpful then you trying to describe it. Sounds like you need to define SA2 as a string.

Code: Select all

string sa2 (a3).
COMPUTE SA2 = CHAR.SUBSTR(A1,CHAR.LENGTH(A1)-5,3). 
EXECUTE.
helenspain
Posts: 4
Joined: Wed Feb 13, 2013 12:51 pm

Re: CHAR.SUBSTR & CHAR.LENGTH

Postby helenspain » Wed Feb 13, 2013 3:58 pm

Thanks for replying, but still not working. :?

I'm pasting the error, but it's in spanish, so I'm translating it for you:

>Error # 4309 en columna1024. Texto: (Fin del comando) - End of the command.
>Combinación no válida de tipos de datos de una asignación.
Not valid combination of data of an allocation.
Las cadenas de caracteres sólo pueden asignarse a variables de cadenas.
Character strings only can be allocated to string variables.
Plantéese utilizar la función STRING.
Use the STRING function. ---> That's your suggestion, but this is the error after using STRING, the same error ever :| .
>La ejecución de este comando se detiene.
Execution will stop.

STRING (SA2) (A3).
COMPUTE SA2 = CHAR.SUBSTR(A1,CHAR.LENGTH(A1)-5,3).
EXECUTE.


Sorry for a messy translation,
I appreciate your help.
Thanks.
JonPedersen
Posts: 119
Joined: Wed May 25, 2011 7:07 am
Contact:

Re: CHAR.SUBSTR & CHAR.LENGTH

Postby JonPedersen » Wed Feb 13, 2013 4:31 pm

hi,
your string syntax is wrong, there should not be any parenthesis around A2.
jon
helenspain
Posts: 4
Joined: Wed Feb 13, 2013 12:51 pm

Re: CHAR.SUBSTR & CHAR.LENGTH

Postby helenspain » Wed Feb 13, 2013 4:59 pm

Ok, I've removed them. Fail XD
But still the same error without them.
:shock:
helenspain
Posts: 4
Joined: Wed Feb 13, 2013 12:51 pm

Re: CHAR.SUBSTR & CHAR.LENGTH

Postby helenspain » Wed Feb 13, 2013 5:07 pm

Problem solved! Now It works with the same syntax, I'm wondering why :D
Thank you guys, you save my MD.

Who is online

Users browsing this forum: No registered users and 2 guests

cron