Testing variable type

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

Testing variable type

peter link

Hello –

 

I’m working with SPSS v12.

 

Is it possible to test the variable type? (Or workarounds?) Long story short – I get many SPSS files, all with the same variable names,  but for whatever reason a variable that is usually a string, on occasion might show up in a file as numeric.

 

I couldn’t find anything relevant in the archives and my FM wasn’t particularly friendly in this instance.

 

Basically I just want to do:

 

DO IF var1 is string.

.

.

.

END IF.

 

DO IF var1 is numeric.

.

.

.

END IF.

 

Thanks for any suggestions.

 

Peter

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

Bruce Weaver
Administrator
Peter, before people expend too much energy trying to remember what features were available in v12 (which was quite a while ago for many of us), please confirm that you really meant v12, and that it was not a typo for v21.  Thanks.  ;-)



peter link wrote
Hello -

 

I'm working with SPSS v12.

 

Is it possible to test the variable type? (Or workarounds?) Long story short
- I get many SPSS files, all with the same variable names,  but for whatever
reason a variable that is usually a string, on occasion might show up in a
file as numeric.

 

I couldn't find anything relevant in the archives and my FM wasn't
particularly friendly in this instance.

 

Basically I just want to do:

 

DO IF var1 is string.

.

.

.

END IF.

 

DO IF var1 is numeric.

.

.

.

END IF.

 

Thanks for any suggestions.

 

Peter


=====================
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
--
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/).
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

peter link
As hard as it is to believe, I do use version twelve. :-)

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Bruce Weaver
Sent: Thursday, October 02, 2014 1:20 PM
To: [hidden email]
Subject: Re: [SPSSX-L] Testing variable type

Peter, before people expend too much energy trying to remember what features
were available in v12 (which was quite a while ago for many of us), please
confirm that you really meant v12, and that it was not a typo for v21.
Thanks.  ;-)




peter link wrote

> Hello -
>
>  
>
> I'm working with SPSS v12.
>
>  
>
> Is it possible to test the variable type? (Or workarounds?) Long story
> short
> - I get many SPSS files, all with the same variable names,  but for
> whatever
> reason a variable that is usually a string, on occasion might show up in a
> file as numeric.
>
>  
>
> I couldn't find anything relevant in the archives and my FM wasn't
> particularly friendly in this instance.
>
>  
>
> Basically I just want to do:
>
>  
>
> DO IF var1 is string.
>
> .
>
> .
>
> .
>
> END IF.
>
>  
>
> DO IF var1 is numeric.
>
> .
>
> .
>
> .
>
> END IF.
>
>  
>
> Thanks for any suggestions.
>
>  
>
> Peter
>
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp572747
1p5727472.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

Tim AT Home
It aint hard at all - I still run version 14 - I do have them all  (but
still today or at least version 22 the stuff wont run what it ran is
versions up to 15 ..)
and I'm tired of pointing out the errors in their program ..




Notice: This e-mail and any attachments may contain confidential and
privileged information.  If you are not the intended recipient, please
notify the sender immediately by return e-mail, do not use the information,
delete this e-mail and destroy any copies.  Any dissemination or use of this
information by a person other than the intended recipient is unauthorized
and may be illegal.  Email transmissions cannot be guaranteed to be secure
or error free. The sender therefore does not accept any liability for errors
or omissions in the contents of this message that arise as a result of email
transmissions.


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Peter Link
Sent: Thursday, October 02, 2014 4:34 PM
To: [hidden email]
Subject: Re: Testing variable type

As hard as it is to believe, I do use version twelve. :-)

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Bruce Weaver
Sent: Thursday, October 02, 2014 1:20 PM
To: [hidden email]
Subject: Re: [SPSSX-L] Testing variable type

Peter, before people expend too much energy trying to remember what features
were available in v12 (which was quite a while ago for many of us), please
confirm that you really meant v12, and that it was not a typo for v21.
Thanks.  ;-)




peter link wrote

> Hello -
>
>  
>
> I'm working with SPSS v12.
>
>  
>
> Is it possible to test the variable type? (Or workarounds?) Long story
> short
> - I get many SPSS files, all with the same variable names,  but for
> whatever reason a variable that is usually a string, on occasion might
> show up in a file as numeric.
>
>  
>
> I couldn't find anything relevant in the archives and my FM wasn't
> particularly friendly in this instance.
>
>  
>
> Basically I just want to do:
>
>  
>
> DO IF var1 is string.
>
> .
>
> .
>
> .
>
> END IF.
>
>  
>
> DO IF var1 is numeric.
>
> .
>
> .
>
> .
>
> END IF.
>
>  
>
> Thanks for any suggestions.
>
>  
>
> Peter
>
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp572747
1p5727472.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

=====================
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

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

Rick Oliver-3
In reply to this post by peter link
Then I think the answer is probably "You can't get there from here" -- or at least you can't get there easily.

This type of operation is relatively easy with the Python plug-in, but that wasn't introduced until version 14.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        Peter Link <[hidden email]>
To:        [hidden email]
Date:        10/02/2014 03:50 PM
Subject:        Re: Testing variable type
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




As hard as it is to believe, I do use version twelve. :-)

-----Original Message-----
From: SPSSX(r) Discussion [
[hidden email]] On Behalf Of
Bruce Weaver
Sent: Thursday, October 02, 2014 1:20 PM
To: [hidden email]
Subject: Re: [SPSSX-L] Testing variable type

Peter, before people expend too much energy trying to remember what features
were available in v12 (which was quite a while ago for many of us), please
confirm that you really meant v12, and that it was not a typo for v21.
Thanks.  ;-)




peter link wrote
> Hello -
>
>  
>
> I'm working with SPSS v12.
>
>  
>
> Is it possible to test the variable type? (Or workarounds?) Long story
> short
> - I get many SPSS files, all with the same variable names,  but for
> whatever
> reason a variable that is usually a string, on occasion might show up in a
> file as numeric.
>
>  
>
> I couldn't find anything relevant in the archives and my FM wasn't
> particularly friendly in this instance.
>
>  
>
> Basically I just want to do:
>
>  
>
> DO IF var1 is string.
>
> .
>
> .
>
> .
>
> END IF.
>
>  
>
> DO IF var1 is numeric.
>
> .
>
> .
>
> .
>
> END IF.
>
>  
>
> Thanks for any suggestions.
>
>  
>
> Peter
>
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp572747
1p5727472.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

=====================
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


===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

David Marso
Administrator
One could most likely get there with a SAX Basic script in versions 7.x to whenever!
-------
Rick Oliver wrote
Then I think the answer is probably "You can't get there from here" -- or
at least you can't get there easily.

This type of operation is relatively easy with the Python plug-in, but
that wasn't introduced until version 14.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]



From:   Peter Link <[hidden email]>
To:     [hidden email]
Date:   10/02/2014 03:50 PM
Subject:        Re: Testing variable type
Sent by:        "SPSSX(r) Discussion" <[hidden email]>



As hard as it is to believe, I do use version twelve. :-)

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Bruce Weaver
Sent: Thursday, October 02, 2014 1:20 PM
To: [hidden email]
Subject: Re: [SPSSX-L] Testing variable type

Peter, before people expend too much energy trying to remember what
features
were available in v12 (which was quite a while ago for many of us), please
confirm that you really meant v12, and that it was not a typo for v21.
Thanks.  ;-)




peter link wrote
> Hello -
>
>
>
> I'm working with SPSS v12.
>
>
>
> Is it possible to test the variable type? (Or workarounds?) Long story
> short
> - I get many SPSS files, all with the same variable names,  but for
> whatever
> reason a variable that is usually a string, on occasion might show up in
a
> file as numeric.
>
>
>
> I couldn't find anything relevant in the archives and my FM wasn't
> particularly friendly in this instance.
>
>
>
> Basically I just want to do:
>
>
>
> DO IF var1 is string.
>
> .
>
> .
>
> .
>
> END IF.
>
>
>
> DO IF var1 is numeric.
>
> .
>
> .
>
> .
>
> END IF.
>
>
>
> Thanks for any suggestions.
>
>
>
> Peter
>
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp572747

1p5727472.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

=====================
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



=====================
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
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?"
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

Rick Oliver-3
You are probably correct.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        David Marso <[hidden email]>
To:        [hidden email]
Date:        10/02/2014 04:14 PM
Subject:        Re: Testing variable type
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




One could most likely get there with a SAX Basic script in versions 7.x to
whenever!
-------

Rick Oliver wrote
> Then I think the answer is probably "You can't get there from here" -- or
> at least you can't get there easily.
>
> This type of operation is relatively easy with the Python plug-in, but
> that wasn't introduced until version 14.
>
> Rick Oliver
> Senior Information Developer
> IBM Business Analytics (SPSS)
> E-mail:

> oliverr@.ibm

>
>
>
> From:   Peter Link &lt;

> plink@.ucsd

> &gt;
> To:    

> SPSSX-L@.UGA

> Date:   10/02/2014 03:50 PM
> Subject:        Re: Testing variable type
> Sent by:        "SPSSX(r) Discussion" &lt;

> SPSSX-L@.UGA

> &gt;
>
>
>
> As hard as it is to believe, I do use version twelve. :-)
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of
> Bruce Weaver
> Sent: Thursday, October 02, 2014 1:20 PM
> To:

> SPSSX-L@.UGA

> Subject: Re: [SPSSX-L] Testing variable type
>
> Peter, before people expend too much energy trying to remember what
> features
> were available in v12 (which was quite a while ago for many of us), please
> confirm that you really meant v12, and that it was not a typo for v21.
> Thanks.  ;-)
>
>
>
>
> peter link wrote
>> Hello -
>>
>>
>>
>> I'm working with SPSS v12.
>>
>>
>>
>> Is it possible to test the variable type? (Or workarounds?) Long story
>> short
>> - I get many SPSS files, all with the same variable names,  but for
>> whatever
>> reason a variable that is usually a string, on occasion might show up in
> a
>> file as numeric.
>>
>>
>>
>> I couldn't find anything relevant in the archives and my FM wasn't
>> particularly friendly in this instance.
>>
>>
>>
>> Basically I just want to do:
>>
>>
>>
>> DO IF var1 is string.
>>
>> .
>>
>> .
>>
>> .
>>
>> END IF.
>>
>>
>>
>> DO IF var1 is numeric.
>>
>> .
>>
>> .
>>
>> .
>>
>> END IF.
>>
>>
>>
>> Thanks for any suggestions.
>>
>>
>>
>> Peter
>>
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (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
>
>
>
>
>
> -----
> --
> Bruce Weaver

> bweaver@

>
http://sites.google.com/a/lakeheadu.ca/bweaver/
>
> "When all else fails, RTFM."
>
> NOTE: My Hotmail account is not monitored regularly.
> To send me an e-mail, please use the address shown above.
>
> --
> View this message in context:
>
http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp572747
>
> 1p5727472.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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
>
>
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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





-----
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?"
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp5727471p5727477.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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


===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

Jon K Peck
In reply to this post by peter link
I'm sorry that this won't help with V12, but for the benefit of others who might have this problem, the STATS ADJUST WIDTH extension command, which works with V18 or later, will generate a report of type mismatches.  This is a common problem with Excel imports.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Peter Link <[hidden email]>
To:        [hidden email]
Date:        10/02/2014 02:50 PM
Subject:        Re: [SPSSX-L] Testing variable type
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




As hard as it is to believe, I do use version twelve. :-)

-----Original Message-----
From: SPSSX(r) Discussion [
[hidden email]] On Behalf Of
Bruce Weaver
Sent: Thursday, October 02, 2014 1:20 PM
To: [hidden email]
Subject: Re: [SPSSX-L] Testing variable type

Peter, before people expend too much energy trying to remember what features
were available in v12 (which was quite a while ago for many of us), please
confirm that you really meant v12, and that it was not a typo for v21.
Thanks.  ;-)




peter link wrote
> Hello -
>
>  
>
> I'm working with SPSS v12.
>
>  
>
> Is it possible to test the variable type? (Or workarounds?) Long story
> short
> - I get many SPSS files, all with the same variable names,  but for
> whatever
> reason a variable that is usually a string, on occasion might show up in a
> file as numeric.
>
>  
>
> I couldn't find anything relevant in the archives and my FM wasn't
> particularly friendly in this instance.
>
>  
>
> Basically I just want to do:
>
>  
>
> DO IF var1 is string.
>
> .
>
> .
>
> .
>
> END IF.
>
>  
>
> DO IF var1 is numeric.
>
> .
>
> .
>
> .
>
> END IF.
>
>  
>
> Thanks for any suggestions.
>
>  
>
> Peter
>
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp572747
1p5727472.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

=====================
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


===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

Bruce Weaver
Administrator
In reply to this post by David Marso
Peter might find some clues about how to do that in file number 1 here:

  http://spsstools.net/SampleScripts.htm#DataDoc

Or if not there, perhaps elsewhere on that site.  


David Marso wrote
One could most likely get there with a SAX Basic script in versions 7.x to whenever!
-------
Rick Oliver wrote
Then I think the answer is probably "You can't get there from here" -- or
at least you can't get there easily.

This type of operation is relatively easy with the Python plug-in, but
that wasn't introduced until version 14.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]



From:   Peter Link <[hidden email]>
To:     [hidden email]
Date:   10/02/2014 03:50 PM
Subject:        Re: Testing variable type
Sent by:        "SPSSX(r) Discussion" <[hidden email]>



As hard as it is to believe, I do use version twelve. :-)

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Bruce Weaver
Sent: Thursday, October 02, 2014 1:20 PM
To: [hidden email]
Subject: Re: [SPSSX-L] Testing variable type

Peter, before people expend too much energy trying to remember what
features
were available in v12 (which was quite a while ago for many of us), please
confirm that you really meant v12, and that it was not a typo for v21.
Thanks.  ;-)




peter link wrote
> Hello -
>
>
>
> I'm working with SPSS v12.
>
>
>
> Is it possible to test the variable type? (Or workarounds?) Long story
> short
> - I get many SPSS files, all with the same variable names,  but for
> whatever
> reason a variable that is usually a string, on occasion might show up in
a
> file as numeric.
>
>
>
> I couldn't find anything relevant in the archives and my FM wasn't
> particularly friendly in this instance.
>
>
>
> Basically I just want to do:
>
>
>
> DO IF var1 is string.
>
> .
>
> .
>
> .
>
> END IF.
>
>
>
> DO IF var1 is numeric.
>
> .
>
> .
>
> .
>
> END IF.
>
>
>
> Thanks for any suggestions.
>
>
>
> Peter
>
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp572747

1p5727472.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

=====================
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



=====================
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
--
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/).
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

King Douglas
Excellent idea, Bruce.  

However, I think this could be done in version 12...and if I were smart
enough and not hungry, I'd provide working code herewith.

If the first case has no missing values for the numeric variables, you could
keep the first case, flip the file and compute a new variable to identify
string and numeric variables (because all the string variable values would
be converted to SYSMIS in the flipped file). [If there are missing values in
the first case or the original file, then someone can help solve that
problem.]

Flag the two variable types in the flipped file, e.g,

COMPUTE TypeFlag = 1.
IF Var001 GT 0, TypeFlag = 2.

VALUE LABELS TypeFlag
  1 'StringVar'
  2 'NumericVar'.

Using the flipped file, WRITE a syntax file that creates a flag for variable
type for each variable. (SPSSTools.net provides sample code).

Run that syntax file to create two data files, NumericVars and StringVars,
retaining all numeric variables in the first file and all the string
variables in the second file.

Then either work with the two files individually or add the two files,
identifying  which is which, e.g.,

ADD FILES
  /FILE = 'c:/numericvars.sav'
  /IN = NumericVars
  /FILE = 'c:/stringvars.sav'
  /IN = StringVars.

* Do what you want to do.

DO IF NumericVars.
DO SOMETHING.
ELSE IF StringVars.
DO SOMETHING ELSE.
END IF.

This will cause warnings that can probably be ignored, but it should get the
job done.


King Douglas

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Bruce Weaver
Sent: Thursday, October 02, 2014 5:07 PM
To: [hidden email]
Subject: Re: Testing variable type

Peter might find some clues about how to do that in file number 1 here:

  http://spsstools.net/SampleScripts.htm#DataDoc

Or if not there, perhaps elsewhere on that site.  



David Marso wrote
> One could most likely get there with a SAX Basic script in versions 7.x to
> whenever!
> -------
> Rick Oliver wrote
>> Then I think the answer is probably "You can't get there from here" -- or

>> at least you can't get there easily.
>>
>> This type of operation is relatively easy with the Python plug-in, but
>> that wasn't introduced until version 14.
>>
>> Rick Oliver
>> Senior Information Developer
>> IBM Business Analytics (SPSS)
>> E-mail:

>> oliverr@.ibm

>>
>>
>>
>> From:   Peter Link &lt;

>> plink@.ucsd

>> &gt;
>> To:    

>> SPSSX-L@.UGA

>> Date:   10/02/2014 03:50 PM
>> Subject:        Re: Testing variable type
>> Sent by:        "SPSSX(r) Discussion" &lt;

>> SPSSX-L@.UGA

>> &gt;
>>
>>
>>
>> As hard as it is to believe, I do use version twelve. :-)
>>
>> -----Original Message-----
>> From: SPSSX(r) Discussion [mailto:

>> SPSSX-L@.UGA

>> ] On Behalf Of
>> Bruce Weaver
>> Sent: Thursday, October 02, 2014 1:20 PM
>> To:

>> SPSSX-L@.UGA

>> Subject: Re: [SPSSX-L] Testing variable type
>>
>> Peter, before people expend too much energy trying to remember what
>> features
>> were available in v12 (which was quite a while ago for many of us),
>> please
>> confirm that you really meant v12, and that it was not a typo for v21.
>> Thanks.  ;-)
>>
>>
>>
>>
>> peter link wrote
>>> Hello -
>>>
>>>
>>>
>>> I'm working with SPSS v12.
>>>
>>>
>>>
>>> Is it possible to test the variable type? (Or workarounds?) Long story
>>> short
>>> - I get many SPSS files, all with the same variable names,  but for
>>> whatever
>>> reason a variable that is usually a string, on occasion might show up in

>> a
>>> file as numeric.
>>>
>>>
>>>
>>> I couldn't find anything relevant in the archives and my FM wasn't
>>> particularly friendly in this instance.
>>>
>>>
>>>
>>> Basically I just want to do:
>>>
>>>
>>>
>>> DO IF var1 is string.
>>>
>>> .
>>>
>>> .
>>>
>>> .
>>>
>>> END IF.
>>>
>>>
>>>
>>> DO IF var1 is numeric.
>>>
>>> .
>>>
>>> .
>>>
>>> .
>>>
>>> END IF.
>>>
>>>
>>>
>>> Thanks for any suggestions.
>>>
>>>
>>>
>>> Peter
>>>
>>>
>>> =====================
>>> To manage your subscription to SPSSX-L, send a message to
>>
>>> LISTSERV@.UGA
>>
>>>  (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
>>
>>
>>
>>
>>
>> -----
>> --
>> Bruce Weaver

>> bweaver@

>> http://sites.google.com/a/lakeheadu.ca/bweaver/
>>
>> "When all else fails, RTFM."
>>
>> NOTE: My Hotmail account is not monitored regularly.
>> To send me an e-mail, please use the address shown above.
>>
>> --
>> View this message in context:
>>
http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp572747
>>
>> 1p5727472.html
>> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to

>> LISTSERV@.UGA

>>  (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
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to

>> LISTSERV@.UGA

>>  (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
>>
>>
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to

>> LISTSERV@.UGA

>>  (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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp572747
1p5727480.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

Albert-Jan Roskam-2
In reply to this post by peter link
Oh, I thought you might suggest this trick (see some other post of yours, way back):

PRESERVE.
SET ERRORS = NONE.
COMPUTE n = NUMBER(s, F5). /* fails if s is a numeric var.
RESTORE.

This is somewhat like this try-except in Python:
try:
    spss.Submit("COMPUTE n = NUMBER(s, F5).")
except:
    pass

An anti-idiom, but it might work.

Albert-Jan


------------------------------
On Thu, Oct 2, 2014 11:06 PM CEST David Marso wrote:

>One could most likely get there with a SAX Basic script in versions 7.x to
>whenever!
>-------
>
>Rick Oliver wrote
>> Then I think the answer is probably "You can't get there from here" -- or
>> at least you can't get there easily.
>>
>> This type of operation is relatively easy with the Python plug-in, but
>> that wasn't introduced until version 14.
>>
>> Rick Oliver
>> Senior Information Developer
>> IBM Business Analytics (SPSS)
>> E-mail:
>
>> oliverr@.ibm
>
>>
>>
>>
>> From:   Peter Link <
>
>> plink@.ucsd
>
>> >
>> To:    
>
>> SPSSX-L@.UGA
>
>> Date:   10/02/2014 03:50 PM
>> Subject:        Re: Testing variable type
>> Sent by:        "SPSSX(r) Discussion" <
>
>> SPSSX-L@.UGA
>
>> >
>>
>>
>>
>> As hard as it is to believe, I do use version twelve. :-)
>>
>> -----Original Message-----
>> From: SPSSX(r) Discussion [mailto:
>
>> SPSSX-L@.UGA
>
>> ] On Behalf Of
>> Bruce Weaver
>> Sent: Thursday, October 02, 2014 1:20 PM
>> To:
>
>> SPSSX-L@.UGA
>
>> Subject: Re: [SPSSX-L] Testing variable type
>>
>> Peter, before people expend too much energy trying to remember what
>> features
>> were available in v12 (which was quite a while ago for many of us), please
>> confirm that you really meant v12, and that it was not a typo for v21.
>> Thanks.  ;-)
>>
>>
>>
>>
>> peter link wrote
>> Hello -
>>
>>
>>
>> I'm working with SPSS v12.
>>
>>
>>
>> Is it possible to test the variable type? (Or workarounds?) Long story
>> short
>> - I get many SPSS files, all with the same variable names,  but for
>> whatever
>> reason a variable that is usually a string, on occasion might show up in
>> a
>> file as numeric.
>>
>>
>>
>> I couldn't find anything relevant in the archives and my FM wasn't
>> particularly friendly in this instance.
>>
>>
>>
>> Basically I just want to do:
>>
>>
>>
>> DO IF var1 is string.
>>
>> .
>>
>> .
>>
>> .
>>
>> END IF.
>>
>>
>>
>> DO IF var1 is numeric.
>>
>> .
>>
>> .
>>
>> .
>>
>> END IF.
>>
>>
>>
>> Thanks for any suggestions.
>>
>>
>>
>> Peter
>>
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>>
>> LISTSERV@.UGA
>>
>>  (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
>>
>>
>>
>>
>>
>> -----
>> --
>> Bruce Weaver
>
>> bweaver@
>
>> http://sites.google.com/a/lakeheadu.ca/bweaver/
>>
>> "When all else fails, RTFM."
>>
>> NOTE: My Hotmail account is not monitored regularly.
>> To send me an e-mail, please use the address shown above.
>>
>> --
>> View this message in context:
>> http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp572747
>>
>> 1p5727472.html
>> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (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
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (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
>>
>>
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (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
>
>
>
>
>
>-----
>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?"
>--
>View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp5727471p5727477.html
>Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
>=====================
>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

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

David Marso
Administrator
In reply to this post by King Douglas
My brain hurts!
Try this in a SAX Basic Script ;=)

Option Explicit
Sub Main
        Dim nvar As Long,i As Long
        Dim vars, pnames,plabels,ptypes,levels,labcnt As Variant
        With objSpssApp.Documents.GetDataDoc(0)
                nvar=.GetNumberOfVariables
                Set vars=.GetVariableInfo(pnames,plabels,ptypes,levels,labcnt)
                For i=0 To nvar-1
                        If ptypes(i) =0 Then
                                objSpssApp.ExecuteCommands ("DESC " & pnames(i) & ".",False)
                        Else
                                objSpssApp.ExecuteCommands ("FREQ " & pnames(i) & ".",False)
                        End If
                Next
        End With
End Sub
King Douglas wrote
Excellent idea, Bruce.  

However, I think this could be done in version 12...and if I were smart
enough and not hungry, I'd provide working code herewith.

If the first case has no missing values for the numeric variables, you could
keep the first case, flip the file and compute a new variable to identify
string and numeric variables (because all the string variable values would
be converted to SYSMIS in the flipped file). [If there are missing values in
the first case or the original file, then someone can help solve that
problem.]

Flag the two variable types in the flipped file, e.g,

COMPUTE TypeFlag = 1.
IF Var001 GT 0, TypeFlag = 2.

VALUE LABELS TypeFlag
  1 'StringVar'
  2 'NumericVar'.

Using the flipped file, WRITE a syntax file that creates a flag for variable
type for each variable. (SPSSTools.net provides sample code).

Run that syntax file to create two data files, NumericVars and StringVars,
retaining all numeric variables in the first file and all the string
variables in the second file.

Then either work with the two files individually or add the two files,
identifying  which is which, e.g.,

ADD FILES
  /FILE = 'c:/numericvars.sav'
  /IN = NumericVars
  /FILE = 'c:/stringvars.sav'
  /IN = StringVars.

* Do what you want to do.

DO IF NumericVars.
DO SOMETHING.
ELSE IF StringVars.
DO SOMETHING ELSE.
END IF.

This will cause warnings that can probably be ignored, but it should get the
job done.


King Douglas

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Bruce Weaver
Sent: Thursday, October 02, 2014 5:07 PM
To: [hidden email]
Subject: Re: Testing variable type

Peter might find some clues about how to do that in file number 1 here:

  http://spsstools.net/SampleScripts.htm#DataDoc

Or if not there, perhaps elsewhere on that site.  



David Marso wrote
> One could most likely get there with a SAX Basic script in versions 7.x to
> whenever!
> -------
> Rick Oliver wrote
>> Then I think the answer is probably "You can't get there from here" -- or

>> at least you can't get there easily.
>>
>> This type of operation is relatively easy with the Python plug-in, but
>> that wasn't introduced until version 14.
>>
>> Rick Oliver
>> Senior Information Developer
>> IBM Business Analytics (SPSS)
>> E-mail:

>> oliverr@.ibm

>>
>>
>>
>> From:   Peter Link <

>> plink@.ucsd

>> >
>> To:    

>> SPSSX-L@.UGA

>> Date:   10/02/2014 03:50 PM
>> Subject:        Re: Testing variable type
>> Sent by:        "SPSSX(r) Discussion" <

>> SPSSX-L@.UGA

>> >
>>
>>
>>
>> As hard as it is to believe, I do use version twelve. :-)
>>
>> -----Original Message-----
>> From: SPSSX(r) Discussion [mailto:

>> SPSSX-L@.UGA

>> ] On Behalf Of
>> Bruce Weaver
>> Sent: Thursday, October 02, 2014 1:20 PM
>> To:

>> SPSSX-L@.UGA

>> Subject: Re: [SPSSX-L] Testing variable type
>>
>> Peter, before people expend too much energy trying to remember what
>> features
>> were available in v12 (which was quite a while ago for many of us),
>> please
>> confirm that you really meant v12, and that it was not a typo for v21.
>> Thanks.  ;-)
>>
>>
>>
>>
>> peter link wrote
>>> Hello -
>>>
>>>
>>>
>>> I'm working with SPSS v12.
>>>
>>>
>>>
>>> Is it possible to test the variable type? (Or workarounds?) Long story
>>> short
>>> - I get many SPSS files, all with the same variable names,  but for
>>> whatever
>>> reason a variable that is usually a string, on occasion might show up in

>> a
>>> file as numeric.
>>>
>>>
>>>
>>> I couldn't find anything relevant in the archives and my FM wasn't
>>> particularly friendly in this instance.
>>>
>>>
>>>
>>> Basically I just want to do:
>>>
>>>
>>>
>>> DO IF var1 is string.
>>>
>>> .
>>>
>>> .
>>>
>>> .
>>>
>>> END IF.
>>>
>>>
>>>
>>> DO IF var1 is numeric.
>>>
>>> .
>>>
>>> .
>>>
>>> .
>>>
>>> END IF.
>>>
>>>
>>>
>>> Thanks for any suggestions.
>>>
>>>
>>>
>>> Peter
>>>
>>>
>>> =====================
>>> To manage your subscription to SPSSX-L, send a message to
>>
>>> LISTSERV@.UGA
>>
>>>  (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
>>
>>
>>
>>
>>
>> -----
>> --
>> Bruce Weaver

>> bweaver@

>> http://sites.google.com/a/lakeheadu.ca/bweaver/
>>
>> "When all else fails, RTFM."
>>
>> NOTE: My Hotmail account is not monitored regularly.
>> To send me an e-mail, please use the address shown above.
>>
>> --
>> View this message in context:
>>
http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp572747
>>
>> 1p5727472.html
>> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to

>> LISTSERV@.UGA

>>  (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
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to

>> LISTSERV@.UGA

>>  (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
>>
>>
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to

>> LISTSERV@.UGA

>>  (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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp572747
1p5727480.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

=====================
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
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?"
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

Kirill Orlov
In reply to this post by peter link
One ridiculous but working approach to discover if a value is numeric or string can be based on the fact that function MISSING() takes either type. So, if you make in advance any numeric value missing, the function will  distinguish the two types.

E.g. let VARLIST be a mixture of num and str variables without defined user missing values.

set errors none.
do rep V= VARLIST.
miss val V (lo thru hi). /*Any numeric but not string value gets missing
end rep.
set errors list.

[do your job conditioned on]
...if missing(a var from VARLIST)
[end job]

miss val VARLIST (). /*remove missing status


02.10.2014 21:41, Peter Link пишет:

Hello –

 

I’m working with SPSS v12.

 

Is it possible to test the variable type? (Or workarounds?) Long story short – I get many SPSS files, all with the same variable names,  but for whatever reason a variable that is usually a string, on occasion might show up in a file as numeric.

 

I couldn’t find anything relevant in the archives and my FM wasn’t particularly friendly in this instance.

 

Basically I just want to do:

 

DO IF var1 is string.

.

.

.

END IF.

 

DO IF var1 is numeric.

.

.

.

END IF.

 

Thanks for any suggestions.

 

Peter

===================== 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


===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

Kirill Orlov
In reply to this post by David Marso
Beware: a typo in Command Syntax Reference.
In the bottom section of Universals chapter: Missing value functions (page 96)

VALUE(variable). Numeric or string. Returns the value.... etc

"string" is odd, because it is stated above:

With the exception of the MISSING function, only numeric values can be used as arguments in
missing-value functions.

therefore VALUE() can never return a string value.

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

Art Kendall
In reply to this post by Albert-Jan Roskam-2
building on Jan's use of preserve etc. and generalizing to more variables try something like this.

new file.
data list list /Id(f2) num1 (f1) str1(a1) num2(f1) str2(a1) str3(a1).
begin data
   01 1 a 2 b c
   02 2 d 3 e f
end data.
numeric  test1 to test5 type1 to type5 (f1).
value labels type1 to type5
   1 'string'
   0 'number'.
preserve.
set errors=none.
do repeat myvar = num1 to str3/type = type1 to type5 /test=test1 to test5.
   compute test = myvar-1.
   compute type = sysmis(test).
end repeat.
restore.
list.

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

peter link
Thanks for all of the feedback, SPSSX-L! These suggestions should help me to
solve this problem.

peter

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Art
Kendall
Sent: Friday, October 03, 2014 4:32 AM
To: [hidden email]
Subject: Re: [SPSSX-L] Testing variable type

building on Jan's use of preserve etc. and generalizing to more variables
try
something like this.

new file.
data list list /Id(f2) num1 (f1) str1(a1) num2(f1) str2(a1) str3(a1).
begin data
   01 1 a 2 b c
   02 2 d 3 e f
end data.
numeric  test1 to test5 type1 to type5 (f1).
value labels type1 to type5
   1 'string'
   0 'number'.
preserve.
set errors=none.
do repeat myvar = num1 to str3/type = type1 to type5 /test=test1 to test5.
   compute test = myvar-1.
   compute type = sysmis(test).
end repeat.
restore.
list.





-----
Art Kendall
Social Research Consultants
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Testing-variable-type-tp572747
1p5727486.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

Richard Ristow
In reply to this post by Kirill Orlov
At 05:56 AM 10/3/2014, Kirill Orlov wrote:

>Beware: a typo in Command Syntax Reference.
>In the bottom section of Universals chapter: Missing value functions (page 96)
>
>>VALUE(variable). Numeric or string. Returns the value.... etc
>
>"string" is odd, because it is stated above:
>
>>With the exception of the MISSING function, only numeric values can
>>be used as arguments in missing-value functions.
>
>therefore VALUE() can never return a string value.

Kirill is right, but it sounds to me like more than a typo; it sounds
like SPSS not having thought through how missing values for string
variables should be handled. Logically, VALUE should apply to both
numeric and string variables; and it sounds like whoever was writing
this section of the CSR simply assumed this was the case.

Here are one numeric and one string variable, each with a
user-missing value (SPSS 14 for Windows, but it sounds like there've
been no relevant changes in later versions):

Nin
|-------|-----|---------|-------|-------------|---------------|
|       |     |Frequency|Percent|Valid Percent|Cumulative     |
|       |     |         |       |             |Percent        |
|-------|-----|---------|-------|-------------|---------------|
|Valid  |1    |1        |33.3   |50.0         |50.0           |
|       |3    |1        |33.3   |50.0         |100.0          |
|       |-----|---------|-------|-------------|---------------|
|       |Total|2        |66.7   |100.0        |               |
|-------|-----|---------|-------|-------------|---------------|
|Missing|2    |1        |33.3   |             |               |
|-------|-----|---------|-------|-------------|---------------|
|Total        |3        |100.0  |             |               |
|-------------|---------|-------|-------------|---------------|

Ain
|-------|-----|---------|-------|-------------|---------------|
|       |     |Frequency|Percent|Valid Percent|Cumulative     |
|       |     |         |       |             |Percent        |
|-------|-----|---------|-------|-------------|---------------|
|Valid  |A    |1        |33.3   |50.0         |50.0           |
|       |C    |1        |33.3   |50.0         |100.0          |
|       |-----|---------|-------|-------------|---------------|
|       |Total|2        |66.7   |100.0        |               |
|-------|-----|---------|-------|-------------|---------------|
|Missing|B    |1        |33.3   |             |               |
|-------|-----|---------|-------|-------------|---------------|
|Total        |3        |100.0  |             |               |
|-------------|---------|-------|-------------|---------------|

Now, here is the result of assigning these to new variables, with and
without using the VALUE function:

NUMERIC Nout1 (F2).
STRING  Aout1 (A2).
NUMERIC Nout2 (F2).
STRING  Aout2 (A2).

COMPUTE Nout1 = Nin.
COMPUTE Nout2 = VALUE(Nin).
COMPUTE Aout1 = Ain.
COMPUTE Aout2 = VALUE(Ain).

>Error # 4313 in column 26.  Text: )
>The single argument for the VALUE function must be a numeric variable.
>Expressions are not permitted.
>This command not executed.

LIST.
List
|-----------------------------|---------------------------|
|Output Created               |03-OCT-2014 18:48:30       |
|-----------------------------|---------------------------|
Nin Ain Nout1 Aout1 Nout2 Aout2

   1 A      1  A        1
   2 B      .  B        2
   3 C      3  C        3

Number of cases read:  3    Number of cases listed:  3

First, Kirill is right and the CSR wrong about the behavior of VALUE
on string variables: in fact, it won't work on string variables.

Second, when a numeric variable is used in an expression, if it has a
missing value, the result of that expression is missing: see variable
Nout1. But when a string variable is used in an expression, a missing
value appears to be accepted exactly as a valid one would be: see Aout1.

================================
APPENDIX: Test data and all code
================================
DATA LIST FREE
    / Nin (F2) Ain(A2).
BEGIN DATA
    1 A 2 B 3 C
END DATA.
LIST.

MISSING VALUES Nin (2) Ain ('B').

FREQUENCIES    Nin Ain.

NUMERIC Nout1 (F2).
STRING  Aout1 (A2).
NUMERIC Nout2 (F2).
STRING  Aout2 (A2).

COMPUTE Nout1 = Nin.
COMPUTE Nout2 = VALUE(Nin).
COMPUTE Aout1 = Ain.
COMPUTE Aout2 = VALUE(Ain).

LIST.

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

Kirill Orlov
Richard wrote:
---> ... but it sounds like there've been no relevant changes in later versions

I agree with Richard argument, however I wouldn't be happy to see any radical change in SPSS' treatment of string missing values in future releases. It will affect usage of many already written syntax pieces. So let it be as it is. The decision that the string missing values should go as valid ones in logical expressions may have some consideration behind it, although I hesitate to guess what it might be.



04.10.2014 2:01, Richard Ristow пишет:

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Testing variable type

Jon K Peck
In reply to this post by Richard Ristow
Logically, one should be able to apply a function like VALUE to both string and numeric variables, however, functions can only return one type of result.  The same function cannot return a value type that depends on the type of the argument.  VALUE is, however, not needed for a string variable because

"String user-missing values are treated as missing by statistical and charting procedures and missing
values functions. They are treated as valid in other transformation expressions."

The CSR in the version for the next release of Statistics says this

VALUE. VALUE(variable). Numeric. Returns the value of variable, ignoring user missing-value definitions
for variable, which must be a numeric variable name or a vector reference to a variable name.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Richard Ristow <[hidden email]>
To:        [hidden email]
Date:        10/03/2014 05:04 PM
Subject:        Re: [SPSSX-L] Testing variable type
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




At 05:56 AM 10/3/2014, Kirill Orlov wrote:

>Beware: a typo in Command Syntax Reference.
>In the bottom section of Universals chapter: Missing value functions (page 96)
>
>>VALUE(variable). Numeric or string. Returns the value.... etc
>
>"string" is odd, because it is stated above:
>
>>With the exception of the MISSING function, only numeric values can
>>be used as arguments in missing-value functions.
>
>therefore VALUE() can never return a string value.

Kirill is right, but it sounds to me like more than a typo; it sounds
like SPSS not having thought through how missing values for string
variables should be handled. Logically, VALUE should apply to both
numeric and string variables; and it sounds like whoever was writing
this section of the CSR simply assumed this was the case.

Here are one numeric and one string variable, each with a
user-missing value (SPSS 14 for Windows, but it sounds like there've
been no relevant changes in later versions):

Nin
|-------|-----|---------|-------|-------------|---------------|
|       |     |Frequency|Percent|Valid Percent|Cumulative     |
|       |     |         |       |             |Percent        |
|-------|-----|---------|-------|-------------|---------------|
|Valid  |1    |1        |33.3   |50.0         |50.0           |
|       |3    |1        |33.3   |50.0         |100.0          |
|       |-----|---------|-------|-------------|---------------|
|       |Total|2        |66.7   |100.0        |               |
|-------|-----|---------|-------|-------------|---------------|
|Missing|2    |1        |33.3   |             |               |
|-------|-----|---------|-------|-------------|---------------|
|Total        |3        |100.0  |             |               |
|-------------|---------|-------|-------------|---------------|

Ain
|-------|-----|---------|-------|-------------|---------------|
|       |     |Frequency|Percent|Valid Percent|Cumulative     |
|       |     |         |       |             |Percent        |
|-------|-----|---------|-------|-------------|---------------|
|Valid  |A    |1        |33.3   |50.0         |50.0           |
|       |C    |1        |33.3   |50.0         |100.0          |
|       |-----|---------|-------|-------------|---------------|
|       |Total|2        |66.7   |100.0        |               |
|-------|-----|---------|-------|-------------|---------------|
|Missing|B    |1        |33.3   |             |               |
|-------|-----|---------|-------|-------------|---------------|
|Total        |3        |100.0  |             |               |
|-------------|---------|-------|-------------|---------------|

Now, here is the result of assigning these to new variables, with and
without using the VALUE function:

NUMERIC Nout1 (F2).
STRING  Aout1 (A2).
NUMERIC Nout2 (F2).
STRING  Aout2 (A2).

COMPUTE Nout1 = Nin.
COMPUTE Nout2 = VALUE(Nin).
COMPUTE Aout1 = Ain.
COMPUTE Aout2 = VALUE(Ain).

>Error # 4313 in column 26.  Text: )
>The single argument for the VALUE function must be a numeric variable.
>Expressions are not permitted.
>This command not executed.

LIST.
List
|-----------------------------|---------------------------|
|Output Created               |03-OCT-2014 18:48:30       |
|-----------------------------|---------------------------|
Nin Ain Nout1 Aout1 Nout2 Aout2

  1 A      1  A        1
  2 B      .  B        2
  3 C      3  C        3

Number of cases read:  3    Number of cases listed:  3

First, Kirill is right and the CSR wrong about the behavior of VALUE
on string variables: in fact, it won't work on string variables.

Second, when a numeric variable is used in an expression, if it has a
missing value, the result of that expression is missing: see variable
Nout1. But when a string variable is used in an expression, a missing
value appears to be accepted exactly as a valid one would be: see Aout1.

================================
APPENDIX: Test data and all code
================================
DATA LIST FREE
   / Nin (F2) Ain(A2).
BEGIN DATA
   1 A 2 B 3 C
END DATA.
LIST.

MISSING VALUES Nin (2) Ain ('B').

FREQUENCIES    Nin Ain.

NUMERIC Nout1 (F2).
STRING  Aout1 (A2).
NUMERIC Nout2 (F2).
STRING  Aout2 (A2).

COMPUTE Nout1 = Nin.
COMPUTE Nout2 = VALUE(Nin).
COMPUTE Aout1 = Ain.
COMPUTE Aout2 = VALUE(Ain).

LIST.

=====================
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


===================== 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