Date: Mon, 26 Apr 2010 20:51:14 +0000
Reply-To: Ruben van den Berg <ruben_van_den_berg@hotmail.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Ruben van den Berg <ruben_van_den_berg@hotmail.com>
Subject: Re: Syntax not working
In-Reply-To: <5AB66E3A87B709438143813E78A72DCC1527F120@excnysm95banp.nysemail.nyenet>
Content-Type: multipart/alternative;
Dear Adriana,
If the non numeric character is always in the 9th. position, then the two syntax examples below should work. I guess RANGE could be used as well (but I forgot how) as long as you convert the 9th. character to numeric as in the second example.
HTH,
Ruben van den Berg
Methodologist
TNS NIPO
E: ruben_van_den_berg@hotmail.com
P: +31 20 522 5738
I: www.tns-nipo.com
*Create test data.
data list free/testvar(a12).begin data23882939L12345678123456789end data.
*Example 1, with ANY.
do if any(sub(testvar,9,1), "1","2","3","4","5","6","7","8","9","0").comp newvar=num(sub(testvar,1,8),f8).else.comp newvar=num(testvar,f8).end if.exe.
*Example 2, any non numeric character will be system missing if converted to numeric.
do if mis(num(sub(testvar,9,1)),f1)=1.comp newvar2=num(sub(testvar,1,8),f8).else.comp newvar2=num(testvar,f8).end if.exe.
Date: Mon, 26 Apr 2010 10:27:36 -0400
From: Adriana.FernandezLanier@dcjs.state.ny.us
Subject: Syntax not working
To: SPSSX-L@LISTSERV.UGA.EDU
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.
P Please consider the environment before printing this e-mail.
This e-mail, including any attachments, may be confidential, privileged or otherwise legally protected. It is intended only for the addressee. If you received this e-mail in error or from someone who was not authorized
to send it to you, do not disseminate, copy or otherwise use this e-mail or its attachments. Please notify the sender immediately by reply e-mail and delete the e-mail from your system.
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
[text/html]
|