variable type function?

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

variable type function?

Maguin, Eugene

Is there a function that returns the type of a variable—string or numeric? I’m pretty sure there’s nothing in syntax, but what about extensions accessable to syntax? I’m sure something could be written (has been written) in Python by someone but my use for this is for someone that doesn’t know what python is or whether or not it is installed on their machine. I want to use this function to conditionally execute code that requires a specific variable type. (I took a pass through the Extensions Hub but didn’t see anything obvious (but did see some surprising things!).

Thanks, Gene Maguin

===================== 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: variable type function?

Jon Peck
See if the SPSSINC SELECT VARIABLES extension (Utilities > Define Variable Macro) will do what you want.  It lets you create a macro listing variables that meet various metadata criteria.  For example,
SPSSINC SELECT VARIABLES MACRONAME="!numeric"
/PROPERTIES TYPE=NUMERIC.
would create a macro listing all the numeric variables in the file.  

SPSSINC SELECT VARIABLES MACRONAME="!categorical"
/PROPERTIES LEVEL=NOMINAL ORDINAL  
/OPTIONS ORDER=ALPHA REVERSE=NO  PRINT=YES IFNONE=ERROR SEPARATOR="+".
would create a macro listing all the categorical variables separated by "+".  Useful for CTABLES

It can select based on lots of other criteria such as measurement level, patterns in names, and custom attributes.

There are Python functions that can examine the variable type, but using these directly requires, well, Python.

On Fri, Jan 31, 2020 at 12:01 PM Maguin, Eugene <[hidden email]> wrote:

Is there a function that returns the type of a variable—string or numeric? I’m pretty sure there’s nothing in syntax, but what about extensions accessable to syntax? I’m sure something could be written (has been written) in Python by someone but my use for this is for someone that doesn’t know what python is or whether or not it is installed on their machine. I want to use this function to conditionally execute code that requires a specific variable type. (I took a pass through the Extensions Hub but didn’t see anything obvious (but did see some surprising things!).

Thanks, Gene Maguin

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


--
Jon K Peck
[hidden email]

===================== 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: variable type function?

Maguin, Eugene

Thank you.

 

From: Jon Peck [mailto:[hidden email]]
Sent: Friday, January 31, 2020 3:27 PM
To: Maguin, Eugene <[hidden email]>
Cc: SPSS List <[hidden email]>
Subject: Re: [SPSSX-L] variable type function?

 

See if the SPSSINC SELECT VARIABLES extension (Utilities > Define Variable Macro) will do what you want.  It lets you create a macro listing variables that meet various metadata criteria.  For example,

SPSSINC SELECT VARIABLES MACRONAME="!numeric"
/PROPERTIES TYPE=NUMERIC.

would create a macro listing all the numeric variables in the file.  

 

SPSSINC SELECT VARIABLES MACRONAME="!categorical"
/PROPERTIES LEVEL=NOMINAL ORDINAL  
/OPTIONS ORDER=ALPHA REVERSE=NO  PRINT=YES IFNONE=ERROR SEPARATOR="+".

would create a macro listing all the categorical variables separated by "+".  Useful for CTABLES

 

It can select based on lots of other criteria such as measurement level, patterns in names, and custom attributes.

 

There are Python functions that can examine the variable type, but using these directly requires, well, Python.

 

On Fri, Jan 31, 2020 at 12:01 PM Maguin, Eugene <[hidden email]> wrote:

Is there a function that returns the type of a variable—string or numeric? I’m pretty sure there’s nothing in syntax, but what about extensions accessable to syntax? I’m sure something could be written (has been written) in Python by someone but my use for this is for someone that doesn’t know what python is or whether or not it is installed on their machine. I want to use this function to conditionally execute code that requires a specific variable type. (I took a pass through the Extensions Hub but didn’t see anything obvious (but did see some surprising things!).

Thanks, Gene Maguin

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


 

--

Jon K Peck
[hidden email]

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