Creating New Value Labels that Include Variable Name from List

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

Creating New Value Labels that Include Variable Name from List

cco14
Hello,

  I’m attempting to write syntax in SPSS that will give new value labels to
a list of about 70 variables in the following format:

Value Labels
*variable*
0 ‘No_*variable name*’
1 ‘Yes_*variable name*’

I’m doing this because I later create a custom table of frequencies that I
do an OMS Export with and these value labels will later become variable
names. I’m betting this is possible, I just don’t have the skills to figure
it out.

This is my sad attempt which is definitely not working as is:

Define !renameValues (vlist = !charend('/'))
!do !var !in (!vlist)
!let !nolabel = !concat("No_", !var)
!let  !yeslabel = !concat("Yes_", !var)
value labels
!var
0 !nolabel
1 !yeslabel
!doend
!enddefine.
!renameValues vlist = !variables.

Any help would be so appreciated!




--
Sent from: http://spssx-discussion.1045642.n5.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
Reply | Threaded
Open this post in threaded view
|

Re: Creating New Value Labels that Include Variable Name from List

Jon Peck
Here's a first cut.  I assumed that it is easier to just assign these labels to all numeric variables with a nominal or ordinal measurement level.  If all the names need to be listed or an exception list would be easier, that can be done.  Or if a pattern in the names would work, that is also possible.  Here is the code.  Note that the indentation below matters.

begin program.
import spss, spssaux

vardict = spssaux.VariableDict(variableLevel=['nominal','ordinal'], variableType="numeric")
for v in vardict.variables:
    spss.Submit("VALUE LABELS %s 0 'No_%s' 1 'Yes_%s'" % (v, v, v))
end program.


On Tue, Feb 26, 2019 at 8:49 AM cco14 <[hidden email]> wrote:
Hello,

  I’m attempting to write syntax in SPSS that will give new value labels to
a list of about 70 variables in the following format:

Value Labels
*variable*
0 ‘No_*variable name*’
1 ‘Yes_*variable name*’

I’m doing this because I later create a custom table of frequencies that I
do an OMS Export with and these value labels will later become variable
names. I’m betting this is possible, I just don’t have the skills to figure
it out.

This is my sad attempt which is definitely not working as is:

Define !renameValues (vlist = !charend('/'))
!do !var !in (!vlist)
!let !nolabel = !concat("No_", !var)
!let  !yeslabel = !concat("Yes_", !var)
value labels
!var
0 !nolabel
1 !yeslabel
!doend
!enddefine.
!renameValues vlist = !variables.

Any help would be so appreciated!




--
Sent from: http://spssx-discussion.1045642.n5.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


--
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: Creating New Value Labels that Include Variable Name from List

David Marso-2
In reply to this post by cco14
0 !nolabel
1 !yeslabel

Should be

0 !QUOTE(!nolabel)
1 !QUOTE(!yeslabel)

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