Re Syntax Not working:

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re Syntax Not working:

David Marso
Administrator
Re Syntax Not working:
-------------------------------
This is a PERFECT application of the INDEX function. 
Note the third argument which parses the"haystack".
Others have mentioned ANY, but why bother to bust out all those
characters and quotes when it is not necessary.
Besides, INDEX is efficient and elegant!!!!

DATA LIST /NYSID 1-12 (A).
BEGIN DATA
12345678A
987654321
END DATA
STRING NEW (A9).
COMPUTE New=SUBSTR(NYSID,1,8).
IF INDEX("0123456789",SUBSTR(NYSID,9,1), 1)<>0 NEW=CONCAT(RTRIM(NEW),SUBSTR(NYSID,9,1)).
LIST.
HTH, David
-------------
>ORIGINAL POST FOLLOWS...
                                             
Good morning. For the last few days I've been trying to figure out why the syntax below does not work. My colleague wrote the syntax to do the following "Translated this means if the last (9th) character of a right justified left padded variable is numeric then take the first 9 characters else
Take the first eight characters." Typically we use an identifier variable (NYSID) that includes 8 numeric digits and the last is an alpha (e.g 23882939L). It's much easier to drop the alpha digit and work with a numeric number. However, it's possible that the identifier can vary in length as well as not include the last alpha (agencies forget). My friend wrote the syntax below to account for all this...but I keep getting the following error (see below). Any suggestions would be greatly appreciated. Thanks, A


DO IF char.substr(char.LPAD(NYSID,9),9) in ("1","2","3","4","5","6","7","8","9","0")
COMPUTE VAR00005=char.substr(CHAR.LPAD(NYSID,1,9))
else
COMPUTE VAR00005=char.substr(CHAR.LPAD(NYSID,1,8))
End if.


Error # 4205. Command name: DO IF
The syntax calls for a logical expression but a numeric or character
expression was found.
This command not executed.
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?"