QUESTION ON CHECKING STRING TYPE

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

QUESTION ON CHECKING STRING TYPE

Krampner, John
We use SPSS Version 14. Can anyone tell me if there is syntax that allows you to test if a variable is STRING or NUMERIC type ?
 


John Krampner | City Research Scientist II
NYC Center for Economic Opportunity
Tel. (212) 331-4708 | Fax (212) 331-4692
[hidden email] | nyc.gov/ceo

 
Reply | Threaded
Open this post in threaded view
|

Re: QUESTION ON CHECKING STRING TYPE

Art Kendall
If I recall correctly that the feature existed back then, the "variables view" should show that info.

Also something like this syntax should work.

DISPLAY VARIABLES /VARIABLES = VARA VARB .

Art Kendall
Social Research Consultants

On 10/14/2010 12:10 PM, Krampner, John wrote:
We use SPSS Version 14. Can anyone tell me if there is syntax that allows you to test if a variable is STRING or NUMERIC type ?
 


John Krampner | City Research Scientist II
NYC Center for Economic Opportunity
Tel. (212) 331-4708 | Fax (212) 331-4692
[hidden email] | nyc.gov/ceo

 
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: QUESTION ON CHECKING STRING TYPE

Art Kendall
Please give us more detail on what you want to do. How does this situation arise?

Guessing that you have a variable list that might have some variables that are strings. In which situation all results
In some circumstances something like this untested syntax might work.
do repeat myvar = vara to vare/ somevar = newvar1 to newvar5.
compute isstring=0.
do if sysmis(myvar/1) .
compute isstring = 1.
compute somevar = -999.
else.
compute somevar =
...

end if.
end repeat
missing values newvar1 to newvar5 (lo thru -1).
add value labels newvar1 to newvar5 -999 ' oops! a string!'.


Art Kendall
Social Research Consultants

On 10/14/2010 1:12 PM, Krampner, John wrote:
Thanks very much for your response. Is there any way this can be used in syntax for an IF statement, ie "IF VARA=STRING, DO SOMETHING" ?


From: Art Kendall [[hidden email]]
Sent: Thursday, October 14, 2010 12:22 PM
To: Krampner, John
Cc: [hidden email]
Subject: Re: [SPSSX-L] QUESTION ON CHECKING STRING TYPE

If I recall correctly that the feature existed back then, the "variables view" should show that info.

Also something like this syntax should work.

DISPLAY VARIABLES /VARIABLES = VARA VARB .

Art Kendall
Social Research Consultants

On 10/14/2010 12:10 PM, Krampner, John wrote:
We use SPSS Version 14. Can anyone tell me if there is syntax that allows you to test if a variable is STRING or NUMERIC type ?
 


John Krampner | City Research Scientist II
NYC Center for Economic Opportunity
Tel. (212) 331-4708 | Fax (212) 331-4692
[hidden email] | nyc.gov/ceo

 
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: QUESTION ON CHECKING STRING TYPE

Art Kendall
open a new instance of SPSS.  Copy the syntax below into s syntax window. Run the syntax. Is this what you want to do?
This syntax will generate a lot of errors.  But notice that it gives the results you want.
You can uncomment the SET command when you see what it does.
new file.
*set errors=no.
data list list/id (f2), v1 (f1) v2(a1), v3(f1) v4 (a1).
begin data
01 1 '4' 1 '4'
02 2 '5' 2 '5'
03 3 '6' 3 '6'
end data.
numeric new1 to new4 (f1).
do repeat old = v1 to v4 /new= new1 to new4.
do if (old/1.0.) eq $sysmis.
recode old(convert) into new.
ELSE.
recode old(else=copy) into new.
end if.
end repeat.
list.

Art Kendall
Social Research Consultants

On 10/14/2010 2:01 PM, Krampner, John wrote:
Thanks again. What I am trying to do is run a RECODE VARA (CONVERT) INTO VARB on a number of variables if, and only if, the variable is a string.


From: Art Kendall [[hidden email]]
Sent: Thursday, October 14, 2010 1:58 PM
To: Krampner, John; SPSSX-L post
Subject: Re: [SPSSX-L] QUESTION ON CHECKING STRING TYPE

Please give us more detail on what you want to do. How does this situation arise?

Guessing that you have a variable list that might have some variables that are strings. In which situation all results
In some circumstances something like this untested syntax might work.
do repeat myvar = vara to vare/ somevar = newvar1 to newvar5.
compute isstring=0.
do if sysmis(myvar/1) .
compute isstring = 1.
compute somevar = -999.
else.
compute somevar =
...

end if.
end repeat
missing values newvar1 to newvar5 (lo thru -1).
add value labels newvar1 to newvar5 -999 ' oops! a string!'.


Art Kendall
Social Research Consultants

On 10/14/2010 1:12 PM, Krampner, John wrote:
Thanks very much for your response. Is there any way this can be used in syntax for an IF statement, ie "IF VARA=STRING, DO SOMETHING" ?


From: Art Kendall [[hidden email]]
Sent: Thursday, October 14, 2010 12:22 PM
To: Krampner, John
Cc: [hidden email]
Subject: Re: [SPSSX-L] QUESTION ON CHECKING STRING TYPE

If I recall correctly that the feature existed back then, the "variables view" should show that info.

Also something like this syntax should work.

DISPLAY VARIABLES /VARIABLES = VARA VARB .

Art Kendall
Social Research Consultants

On 10/14/2010 12:10 PM, Krampner, John wrote:
We use SPSS Version 14. Can anyone tell me if there is syntax that allows you to test if a variable is STRING or NUMERIC type ?
 


John Krampner | City Research Scientist II
NYC Center for Economic Opportunity
Tel. (212) 331-4708 | Fax (212) 331-4692
[hidden email] | nyc.gov/ceo

 
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: QUESTION ON CHECKING STRING TYPE

John F Hall
In reply to this post by Krampner, John
Is this before or after you have a data editor?  If after, the types are listed in variable view: if before it's string if it has any characters other than numbers in it.  You need to post more details , including sample data, if you want a proper answer.
 
----- Original Message -----
Sent: Thursday, October 14, 2010 6:10 PM
Subject: QUESTION ON CHECKING STRING TYPE

We use SPSS Version 14. Can anyone tell me if there is syntax that allows you to test if a variable is STRING or NUMERIC type ?
 


John Krampner | City Research Scientist II
NYC Center for Economic Opportunity
Tel. (212) 331-4708 | Fax (212) 331-4692
[hidden email] | nyc.gov/ceo

 
Reply | Threaded
Open this post in threaded view
|

Re: QUESTION ON CHECKING STRING TYPE

Bruce Weaver
Administrator
John F Hall wrote
Is this before or after you have a data editor?  If after, the types are listed in variable view: if before it's string if it has any characters other than numbers in it.  You need to post more details , including sample data, if you want a proper answer.

John Hall
johnfhall@orange.fr
http://surveyresearch.weebly.com 
Hi John.  You may have missed that the OP clarified what he was after in a private reply to Art.  I.e.,

On 10/14/2010 2:01 PM, Krampner, John wrote:
> Thanks again. What I am trying to do is run a RECODE VARA (CONVERT) INTO VARB on a number of variables if, and only if, the variable is a string.

This never appeared on the mailing list directly, as far as I know.  I saw it in Art's reply to the list, which included a very nice solution to the problem.

HTH.
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).