Creating set of variables with varying subscripts.

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

Creating set of variables with varying subscripts.

venkatesh gandi
Hi All,

Can any one help me on how to create set of variables with varying subscripts.

For example i have to create the variables List_1, List_3, list_7, List_10.where the number after  [list_ ] are varying.I failed by trying using do repeat.

What if the name itself before the number also varying?

Thanks in advance.
===================== 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 set of variables with varying subscripts.

Bruce Weaver
Administrator
If you post the DO REPEAT syntax that failed, someone may be able to suggest another approach (e.g., a macro).  But from what you said, neither the root variable names nor the extensions follow any consistent pattern.  If that is true, any kind of looping approach is going to be pretty difficult.


venkatesh gandi wrote
Hi All,

Can any one help me on how to create set of variables with varying
subscripts.

For example i have to create the variables List_1, List_3, list_7,
List_10.where the number after  [list_ ] are varying.I failed by trying
using do repeat.

What if the name itself before the number also varying?

Thanks in advance.

=====================
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: Creating set of variables with varying subscripts.

Rich Ulrich
In reply to this post by venkatesh gandi

As illustrated, there is no pattern, so everything needs to be listed.

To create several new variables, you can say either STRING or NUMERIC, like --

NUMERIC  List_1, List_3, List7, List10 .


--
Rich Ulrich


Date: Tue, 19 Jul 2016 04:41:42 +0530
From: [hidden email]
Subject: Creating set of variables with varying subscripts.
To: [hidden email]

Hi All,

Can any one help me on how to create set of variables with varying subscripts.

For example i have to create the variables List_1, List_3, list_7, List_10.where the number after  [list_ ] are varying.I failed by trying using do repeat.

What if the name itself before the number also varying?

Thanks in advance.
===================== 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: Creating set of variables with varying subscripts.

David Marso
Administrator
You need to remove the commas and supply a format.

Rich Ulrich wrote
As illustrated, there is no pattern, so everything needs to be listed.

To create several new variables, you can say either STRING or NUMERIC, like --

NUMERIC  List_1, List_3, List7, List10 .


--
Rich Ulrich

Date: Tue, 19 Jul 2016 04:41:42 +0530
From: [hidden email]
Subject: Creating set of variables with varying subscripts.
To: [hidden email]

Hi All,
Can any one help me on how to create set of variables with varying subscripts.
For example i have to create the variables List_1, List_3, list_7, List_10.where the number after  [list_ ] are varying.I failed by trying using do repeat.
What if the name itself before the number also varying?
Thanks in advance.
=====================
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: Creating set of variables with varying subscripts.

Jon Peck
That NUMERIC syntax is perfectly valid as is.  Commas are optional separators, and the default format would be used.

On Tue, Jul 19, 2016 at 7:40 AM, David Marso <[hidden email]> wrote:
You need to remove the commas and supply a format.


Rich Ulrich wrote
> As illustrated, there is no pattern, so everything needs to be listed.
>
> To create several new variables, you can say either STRING or NUMERIC,
> like --
>
> NUMERIC  List_1, List_3, List7, List10 .
>
>
> --
> Rich Ulrich
>
> Date: Tue, 19 Jul 2016 04:41:42 +0530
> From:

> gandivenkatesh187@

> Subject: Creating set of variables with varying subscripts.
> To:

> SPSSX-L@.UGA

>
> Hi All,
> Can any one help me on how to create set of variables with varying
> subscripts.
> For example i have to create the variables List_1, List_3, list_7,
> List_10.where the number after  [list_ ] are varying.I failed by trying
> using do repeat.
> What if the name itself before the number also varying?
> Thanks in advance.
> =====================
> 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/Creating-set-of-variables-with-varying-subscripts-tp5732781p5732786.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



--
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 set of variables with varying subscripts.

Rich Ulrich
By the way, I have used NUMERIC  to create contiguous variables in two circumstances.

1.  As (I think) the OP discovered to his regret,
    DO REPEAT  /DUM1= v1 to v20    ...
is not a reliable way to create contiguous v1 to v20; DO REPEAT synthesizes all the implied
lines, so that a second set of new variables (/DUM2= z1 to z20)  will result in an ordering like
v1, z1, v2, z2, v3, z3  ... which is seldom what you want.   Or, without a DUM2, you could
accidentally insert some other variable, resulting in (contiguously)   v1, TOTv, v2 to v20

2.  More often, I wanted to initialize a new set of variables.  Conveniently:
  NUMERIC v1 to v20.
  RECODE  v1 to v20(ELSE=0).

--
Rich Ulrich


Date: Tue, 19 Jul 2016 07:44:11 -0600
From: [hidden email]
Subject: Re: Creating set of variables with varying subscripts.
To: [hidden email]

That NUMERIC syntax is perfectly valid as is.  Commas are optional separators, and the default format would be used.

On Tue, Jul 19, 2016 at 7:40 AM, David Marso <[hidden email]> wrote:
You need to remove the commas and supply a format.


Rich Ulrich wrote
> As illustrated, there is no pattern, so everything needs to be listed.
>
> To create several new variables, you can say either STRING or NUMERIC,
> like --
>
> NUMERIC  List_1, List_3, List7, List10 .
>
>
===================== 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 set of variables with varying subscripts.

venkatesh gandi
Hi Bruce,Rich,David & Jon,

Thanks for reply.

@Bruce : Here is the code i had used and failed.And Yes,their is no consistent pattern :| 

VECTOR v=v1 to v5.
DO REPEAT i=1,3,5,7,10
/v_=v1 to v5.
RENAME VARIABLES (v_=List_i).
END REPEAT.
EXE.

and the same thing i had tried in LOOP-END LOOP also. And What i come to know is the value of 'i' not replacing in the variable name.

@Rich: So want you want to to say if their is no pattern then their is no way to programming except creating them manually.Is that Right?

This situation is arises when i want to convert my single answer responses to a multi answer question responses.
For example: Q17 is a variable and may have any one of values 1,2,3,5,98,99(responses for question Q17). Now i want to convert this as multi response questions as the answers storing in the variables like Q17_1, Q17_2,Q17_3,Q17_5,Q17_98,Q17_99.If Q17 has value 5 then Q17_5 has value 1 otherwise it will be 0.


Hope this explanation may solve the problem.

Sorry if i am not clear in the first mail.

On Tue, Jul 19, 2016 at 10:37 PM, Rich Ulrich <[hidden email]> wrote:
By the way, I have used NUMERIC  to create contiguous variables in two circumstances.

1.  As (I think) the OP discovered to his regret,
    DO REPEAT  /DUM1= v1 to v20    ...
is not a reliable way to create contiguous v1 to v20; DO REPEAT synthesizes all the implied
lines, so that a second set of new variables (/DUM2= z1 to z20)  will result in an ordering like
v1, z1, v2, z2, v3, z3  ... which is seldom what you want.   Or, without a DUM2, you could
accidentally insert some other variable, resulting in (contiguously)   v1, TOTv, v2 to v20

2.  More often, I wanted to initialize a new set of variables.  Conveniently:
  NUMERIC v1 to v20.
  RECODE  v1 to v20(ELSE=0).

--
Rich Ulrich


Date: Tue, 19 Jul 2016 07:44:11 -0600
From: [hidden email]
Subject: Re: Creating set of variables with varying subscripts.
To: [hidden email]

That NUMERIC syntax is perfectly valid as is.  Commas are optional separators, and the default format would be used.

On Tue, Jul 19, 2016 at 7:40 AM, David Marso <[hidden email]> wrote:
You need to remove the commas and supply a format.


Rich Ulrich wrote
> As illustrated, there is no pattern, so everything needs to be listed.
>
> To create several new variables, you can say either STRING or NUMERIC,
> like --
>
> NUMERIC  List_1, List_3, List7, List10 .
>
>
===================== 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: Creating set of variables with varying subscripts.

Jon Peck
This doesn't fit exactly, but maybe it will help.  The STATS MCSET CONVERT extension command converts multiple category sets to multiple dichotomy sets based on the input set values.

You have to have at least two variables to define an MC set, so I just set a variable to all sysmis values and defined it like this.
data list list/q17 x.
begin data
1 .
2 .
1 .
3 .
5 .
end data.
MRSETS
  /MCGROUP NAME=$fred VARIABLES=q17 x
  /DISPLAY NAME=[$fred].

Then
STATS MCSET CONVERT mcset=$fred varprefix=Q setname=newset.
creates an MD set named newset containing all the dichotomies.
1.00 1.00 .00 .00 .00
2.00 .00 1.00 .00 .00
1.00 1.00 .00 .00 .00
3.00 .00 .00 1.00 .00
5.00 .00 .00 .00 1.00

Now, the variable names are Q_01, Q_02, Q_03 and Q_04, not based on the values,
but the variable labels are the values.

This might actually be easier to work with



On Tue, Jul 19, 2016 at 12:41 PM, venkatesh gandi <[hidden email]> wrote:
Hi Bruce,Rich,David & Jon,

Thanks for reply.

@Bruce : Here is the code i had used and failed.And Yes,their is no consistent pattern :| 

VECTOR v=v1 to v5.
DO REPEAT i=1,3,5,7,10
/v_=v1 to v5.
RENAME VARIABLES (v_=List_i).
END REPEAT.
EXE.

and the same thing i had tried in LOOP-END LOOP also. And What i come to know is the value of 'i' not replacing in the variable name.

@Rich: So want you want to to say if their is no pattern then their is no way to programming except creating them manually.Is that Right?

This situation is arises when i want to convert my single answer responses to a multi answer question responses.
For example: Q17 is a variable and may have any one of values 1,2,3,5,98,99(responses for question Q17). Now i want to convert this as multi response questions as the answers storing in the variables like Q17_1, Q17_2,Q17_3,Q17_5,Q17_98,Q17_99.If Q17 has value 5 then Q17_5 has value 1 otherwise it will be 0.


Hope this explanation may solve the problem.

Sorry if i am not clear in the first mail.

On Tue, Jul 19, 2016 at 10:37 PM, Rich Ulrich <[hidden email]> wrote:
By the way, I have used NUMERIC  to create contiguous variables in two circumstances.

1.  As (I think) the OP discovered to his regret,
    DO REPEAT  /DUM1= v1 to v20    ...
is not a reliable way to create contiguous v1 to v20; DO REPEAT synthesizes all the implied
lines, so that a second set of new variables (/DUM2= z1 to z20)  will result in an ordering like
v1, z1, v2, z2, v3, z3  ... which is seldom what you want.   Or, without a DUM2, you could
accidentally insert some other variable, resulting in (contiguously)   v1, TOTv, v2 to v20

2.  More often, I wanted to initialize a new set of variables.  Conveniently:
  NUMERIC v1 to v20.
  RECODE  v1 to v20(ELSE=0).

--
Rich Ulrich


Date: Tue, 19 Jul 2016 07:44:11 -0600
From: [hidden email]
Subject: Re: Creating set of variables with varying subscripts.
To: [hidden email]

That NUMERIC syntax is perfectly valid as is.  Commas are optional separators, and the default format would be used.

On Tue, Jul 19, 2016 at 7:40 AM, David Marso <[hidden email]> wrote:
You need to remove the commas and supply a format.


Rich Ulrich wrote
> As illustrated, there is no pattern, so everything needs to be listed.
>
> To create several new variables, you can say either STRING or NUMERIC,
> like --
>
> NUMERIC  List_1, List_3, List7, List10 .
>
>
===================== 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



--
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 set of variables with varying subscripts.

Bruce Weaver
Administrator
Jon, your MRSETS approach works quite nicely.  But it generates indicators only for those values of Q17 that actually appear in the file.  It seemed to me that the OP might want indicators for a set of all possible values, regardless of whether they occur in the dataset or not.  Is there any straightforward way to modify your approach to do that?  

Meanwhile, here is another approach that uses VECTOR.  It assumes that the possible values range from 1 to some known maximum, and that the user knows which indicators between Q17_1 and Q17_max are to be omitted.  I stuck the main code in a macro that takes arguments for the original variable name, the maximum possible value, and a list of indicator variables that can be omitted.

I admit it's not very pretty, but offer it anyway in case the OP finds it useful.  


* The following macro is intended to deal with the question raised here:
http://spssx-discussion.1045642.n5.nabble.com/Creating-set-of-variables-with-varying-subscripts-tp5732781p5732789.html
.
* It assumes that value of Q17 (or whatever variable the user
* selects) ranges from 1 to a known maximum value (MaxVal).
* It also assumes that the user knows which values between 1 and
* MaxVal are not allowed, and it excludes those indicator variables.

* Stick the basic code in a macro.
DEFINE !GO (V = !CHAREND('/') / MaxVal = !CHAREND('/') / DropList = !CMDEND)
!LET !Root = !CONCAT(!V,"_")
!LET !First = !CONCAT(!Root,1)
!LET !Last = !CONCAT(!Root,!MaxVal)
VECTOR !CONCAT(!V,"_")(!MaxVal,F1).
* Initialize all variables to 0.
RECODE !First to !Last (ELSE=0).
* Replace 0 with 1 where appropriate.
************************************.
IF RANGE(!V,1,!MaxVal) !Root(!V) = 1.
************************************.
* Delete the unneeded variables.
* NOTE:  EXECUTE is needed before DELETE VARIABLES.
EXECUTE.
DELETE VARIABLES !DropList.
!ENDDEFINE.

* Test with a dataset containing all possible values of Q17.
NEW FILE.
DATASET CLOSE ALL.
DATA LIST free / Q17 (F2.0).
BEGIN DATA
1,2,3,5,98,99
END DATA.

!GO V = Q17 / MaxVal = 99 / DropList = Q17_4 Q17_6 to Q17_97.
LIST.

List
Q17 Q17_1 Q17_2 Q17_3 Q17_5 Q17_98 Q17_99

  1   1     0     0     0      0      0
  2   0     1     0     0      0      0
  3   0     0     1     0      0      0
  5   0     0     0     1      0      0
 98   0     0     0     0      1      0
 99   0     0     0     0      0      1

Number of cases read:  6    Number of cases listed:  6


* Test with some allowable values of Q17 missing.
* This is the same input data Jon used in his example in the same thread.
DATA LIST free / Q17 (F2.0).
BEGIN DATA
1,2,1,3,5
END DATA.

!GO V = Q17 / MaxVal = 99 / DropList = Q17_4 Q17_6 to Q17_97.
LIST.

List

Q17 Q17_1 Q17_2 Q17_3 Q17_5 Q17_98 Q17_99

  1   1     0     0     0      0      0
  2   0     1     0     0      0      0
  1   1     0     0     0      0      0
  3   0     0     1     0      0      0
  5   0     0     0     1      0      0

Number of cases read:  5    Number of cases listed:  5


* Test with some extraneous values of Q17.
DATA LIST free / Q17 (F5.0).
BEGIN DATA
1,2,3,5,98,99,100,-1,-10,-50
END DATA.

!GO V = Q17 / MaxVal = 99 / DropList = Q17_4 Q17_6 to Q17_97.
LIST.

List

  Q17 Q17_1 Q17_2 Q17_3 Q17_5 Q17_98 Q17_99

    1   1     0     0     0      0      0
    2   0     1     0     0      0      0
    3   0     0     1     0      0      0
    5   0     0     0     1      0      0
   98   0     0     0     0      1      0
   99   0     0     0     0      0      1
  100   0     0     0     0      0      0
   -1   0     0     0     0      0      0
  -10   0     0     0     0      0      0
  -50   0     0     0     0      0      0

Number of cases read:  10    Number of cases listed:  10


* Test with possible values 1-5, 8 and 9, and variable = Item42.
NEW FILE.
DATASET CLOSE ALL.
DATA LIST free / Item42 (F2.0).
BEGIN DATA
1,2,3,4,5,8,9,98,99
END DATA.

!GO V = Item42 / MaxVal = 9 / DropList = Item42_6 Item42_7 .
LIST.

List

Item42 Item42_1 Item42_2 Item42_3 Item42_4 Item42_5 Item42_8 Item42_9

   1       1        0        0        0        0        0        0
   2       0        1        0        0        0        0        0
   3       0        0        1        0        0        0        0
   4       0        0        0        1        0        0        0
   5       0        0        0        0        1        0        0
   8       0        0        0        0        0        1        0
   9       0        0        0        0        0        0        1
  98       0        0        0        0        0        0        0
  99       0        0        0        0        0        0        0

Number of cases read:  9    Number of cases listed:  9


HTH.

Jon Peck wrote
This doesn't fit exactly, but maybe it will help.  The STATS MCSET CONVERT
extension command converts multiple category sets to multiple dichotomy
sets based on the input set values.

You have to have at least two variables to define an MC set, so I just set
a variable to all sysmis values and defined it like this.
data list list/q17 x.
begin data
1 .
2 .
1 .
3 .
5 .
end data.
MRSETS
  /MCGROUP NAME=$fred VARIABLES=q17 x
  /DISPLAY NAME=[$fred].

Then
STATS MCSET CONVERT mcset=$fred varprefix=Q setname=newset.
creates an MD set named newset containing all the dichotomies.
1.00 1.00 .00 .00 .00
2.00 .00 1.00 .00 .00
1.00 1.00 .00 .00 .00
3.00 .00 .00 1.00 .00
5.00 .00 .00 .00 1.00

Now, the variable names are Q_01, Q_02, Q_03 and Q_04, not based on the
values,
but the variable labels are the values.

This might actually be easier to work with



On Tue, Jul 19, 2016 at 12:41 PM, venkatesh gandi <
[hidden email]> wrote:

> Hi Bruce,Rich,David & Jon,
>
> Thanks for reply.
>
> @Bruce : Here is the code i had used and failed.And Yes,their is no
> consistent pattern :|
>
> VECTOR v=v1 to v5.
> DO REPEAT i=1,3,5,7,10
> /v_=v1 to v5.
> RENAME VARIABLES (v_=List_i).
> END REPEAT.
> EXE.
>
> and the same thing i had tried in LOOP-END LOOP also. And What i come to
> know is the value of 'i' not replacing in the variable name.
>
> @Rich: So want you want to to say if their is no pattern then their is no
> way to programming except creating them manually.Is that Right?
>
> This situation is arises when i want to convert my single
> answer responses to a multi answer question responses.
> For example: Q17 is a variable and may have any one of values
> 1,2,3,5,98,99(responses for question Q17). Now i want to convert this as
> multi response questions as the answers storing in the variables like
> Q17_1, Q17_2,Q17_3,Q17_5,Q17_98,Q17_99.If Q17 has value 5 then Q17_5 has
> value 1 otherwise it will be 0.
>
>
> Hope this explanation may solve the problem.
>
> Sorry if i am not clear in the first mail.
--
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: Creating set of variables with varying subscripts.

Art Kendall
In reply to this post by Jon Peck
" just set a variable to all sysmis values"

Would this approach work if user missing values were input.

[My soapbox about missing values being user missing if the user inputs them with sysmis reserved for when the software is unable to follow instructions. Maintaining this distinction user/system missing can be a great aid in validating/referencing/quality assurance.]

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

Re: Creating set of variables with varying subscripts.

Jon Peck
In reply to this post by Bruce Weaver
It would be possible to modify the extension to accept a supplementary list of values, but it would be easier just to write a short piece of dedicated code for this (via standard syntax or Python), since this seems like a pretty rare need.

On Thu, Jul 21, 2016 at 7:32 AM, Bruce Weaver <[hidden email]> wrote:
Jon, your MRSETS approach works quite nicely.  But it generates indicators
only for those values of Q17 that actually appear in the file.  It seemed to
me that the OP might want indicators for a set of /all possible values/,
regardless of whether they occur in the dataset or not.  Is there any
straightforward way to modify your approach to do that?

Meanwhile, here is another approach that uses VECTOR.  It assumes that the
possible values range from 1 to some known maximum, and that the user knows
which indicators between Q17_1 and Q17_max are to be omitted.  I stuck the
main code in a macro that takes arguments for the original variable name,
the maximum possible value, and a list of indicator variables that can be
omitted.

I admit it's not very pretty, but offer it anyway in case the OP finds it
useful.


* The following macro is intended to deal with the question raised here:
http://spssx-discussion.1045642.n5.nabble.com/Creating-set-of-variables-with-varying-subscripts-tp5732781p5732789.html
.
* It assumes that value of Q17 (or whatever variable the user
* selects) ranges from 1 to a known maximum value (MaxVal).
* It also assumes that the user knows which values between 1 and
* MaxVal are not allowed, and it excludes those indicator variables.

* Stick the basic code in a macro.
DEFINE !GO (V = !CHAREND('/') / MaxVal = !CHAREND('/') / DropList = !CMDEND)
!LET !Root = !CONCAT(!V,"_")
!LET !First = !CONCAT(!Root,1)
!LET !Last = !CONCAT(!Root,!MaxVal)
VECTOR !CONCAT(!V,"_")(!MaxVal,F1).
* Initialize all variables to 0.
RECODE !First to !Last (ELSE=0).
* Replace 0 with 1 where appropriate.
************************************.
IF RANGE(!V,1,!MaxVal) !Root(!V) = 1.
************************************.
* Delete the unneeded variables.
* NOTE:  EXECUTE is needed before DELETE VARIABLES.
EXECUTE.
DELETE VARIABLES !DropList.
!ENDDEFINE.

* Test with a dataset containing all possible values of Q17.
NEW FILE.
DATASET CLOSE ALL.
DATA LIST free / Q17 (F2.0).
BEGIN DATA
1,2,3,5,98,99
END DATA.

!GO V = Q17 / MaxVal = 99 / DropList = Q17_4 Q17_6 to Q17_97.
LIST.

List
Q17 Q17_1 Q17_2 Q17_3 Q17_5 Q17_98 Q17_99

  1   1     0     0     0      0      0
  2   0     1     0     0      0      0
  3   0     0     1     0      0      0
  5   0     0     0     1      0      0
 98   0     0     0     0      1      0
 99   0     0     0     0      0      1

Number of cases read:  6    Number of cases listed:  6


* Test with some allowable values of Q17 missing.
* This is the same input data Jon used in his example in the same thread.
DATA LIST free / Q17 (F2.0).
BEGIN DATA
1,2,1,3,5
END DATA.

!GO V = Q17 / MaxVal = 99 / DropList = Q17_4 Q17_6 to Q17_97.
LIST.

List

Q17 Q17_1 Q17_2 Q17_3 Q17_5 Q17_98 Q17_99

  1   1     0     0     0      0      0
  2   0     1     0     0      0      0
  1   1     0     0     0      0      0
  3   0     0     1     0      0      0
  5   0     0     0     1      0      0

Number of cases read:  5    Number of cases listed:  5


* Test with some extraneous values of Q17.
DATA LIST free / Q17 (F5.0).
BEGIN DATA
1,2,3,5,98,99,100,-1,-10,-50
END DATA.

!GO V = Q17 / MaxVal = 99 / DropList = Q17_4 Q17_6 to Q17_97.
LIST.

List

  Q17 Q17_1 Q17_2 Q17_3 Q17_5 Q17_98 Q17_99

    1   1     0     0     0      0      0
    2   0     1     0     0      0      0
    3   0     0     1     0      0      0
    5   0     0     0     1      0      0
   98   0     0     0     0      1      0
   99   0     0     0     0      0      1
  100   0     0     0     0      0      0
   -1   0     0     0     0      0      0
  -10   0     0     0     0      0      0
  -50   0     0     0     0      0      0

Number of cases read:  10    Number of cases listed:  10


* Test with possible values 1-5, 8 and 9, and variable = Item42.
NEW FILE.
DATASET CLOSE ALL.
DATA LIST free / Item42 (F2.0).
BEGIN DATA
1,2,3,4,5,8,9,98,99
END DATA.

!GO V = Item42 / MaxVal = 9 / DropList = Item42_6 Item42_7 .
LIST.

List

Item42 Item42_1 Item42_2 Item42_3 Item42_4 Item42_5 Item42_8 Item42_9

   1       1        0        0        0        0        0        0
   2       0        1        0        0        0        0        0
   3       0        0        1        0        0        0        0
   4       0        0        0        1        0        0        0
   5       0        0        0        0        1        0        0
   8       0        0        0        0        0        1        0
   9       0        0        0        0        0        0        1
  98       0        0        0        0        0        0        0
  99       0        0        0        0        0        0        0

Number of cases read:  9    Number of cases listed:  9


HTH.


Jon Peck wrote
> This doesn't fit exactly, but maybe it will help.  The STATS MCSET CONVERT
> extension command converts multiple category sets to multiple dichotomy
> sets based on the input set values.
>
> You have to have at least two variables to define an MC set, so I just set
> a variable to all sysmis values and defined it like this.
> data list list/q17 x.
> begin data
> 1 .
> 2 .
> 1 .
> 3 .
> 5 .
> end data.
> MRSETS
>   /MCGROUP NAME=$fred VARIABLES=q17 x
>   /DISPLAY NAME=[$fred].
>
> Then
> STATS MCSET CONVERT mcset=$fred varprefix=Q setname=newset.
> creates an MD set named newset containing all the dichotomies.
> 1.00 1.00 .00 .00 .00
> 2.00 .00 1.00 .00 .00
> 1.00 1.00 .00 .00 .00
> 3.00 .00 .00 1.00 .00
> 5.00 .00 .00 .00 1.00
>
> Now, the variable names are Q_01, Q_02, Q_03 and Q_04, not based on the
> values,
> but the variable labels are the values.
>
> This might actually be easier to work with
>
>
>
> On Tue, Jul 19, 2016 at 12:41 PM, venkatesh gandi <

> gandivenkatesh187@

>> wrote:
>
>> Hi Bruce,Rich,David & Jon,
>>
>> Thanks for reply.
>>
>> @Bruce : Here is the code i had used and failed.And Yes,their is no
>> consistent pattern :|
>>
>> VECTOR v=v1 to v5.
>> DO REPEAT i=1,3,5,7,10
>> /v_=v1 to v5.
>> RENAME VARIABLES (v_=List_i).
>> END REPEAT.
>> EXE.
>>
>> and the same thing i had tried in LOOP-END LOOP also. And What i come to
>> know is the value of 'i' not replacing in the variable name.
>>
>> @Rich: So want you want to to say if their is no pattern then their is no
>> way to programming except creating them manually.Is that Right?
>>
>> This situation is arises when i want to convert my single
>> answer responses to a multi answer question responses.
>> For example: Q17 is a variable and may have any one of values
>> 1,2,3,5,98,99(responses for question Q17). Now i want to convert this as
>> multi response questions as the answers storing in the variables like
>> Q17_1, Q17_2,Q17_3,Q17_5,Q17_98,Q17_99.If Q17 has value 5 then Q17_5 has
>> value 1 otherwise it will be 0.
>>
>>
>> Hope this explanation may solve the problem.
>>
>> Sorry if i am not clear in the first mail.





-----
--
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/Creating-set-of-variables-with-varying-subscripts-tp5732781p5732799.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



--
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 set of variables with varying subscripts.

Bruce Weaver
Administrator
In reply to this post by Art Kendall
Hi Art.  Jon included variable x in his example (shown below) because MRSETS needs to have at least two variables listed on the /MCGROUP sub-command.  As far as I can tell, all values of x have to be missing for MRSETS to work as intended in this case.  But they can be either SYSMIS or user-defined missing values.  For example:

* Modificiation of Jon's example.
data list free/q17.
begin data
1 2 1 3 5
end data.

* Add variable x, because MRSETS needs at least 2 variables listed.
IF ANY($casenum,1,3,5) x = -999.
* For Jon's solution to work, all values of x must be missing (I think).
MISSING VALUES x (-999).
MRSETS
  /MCGROUP NAME=$fred VARIABLES=q17 x
  /DISPLAY NAME=[$fred].

STATS MCSET CONVERT mcset=$fred varprefix=Q setname=newset.
LIST.

OUTPUT:

     q17        x     Q_01     Q_02     Q_03     Q_04
 
    1.00  -999.00     1.00      .00      .00      .00
    2.00      .        .00     1.00      .00      .00
    1.00  -999.00     1.00      .00      .00      .00
    3.00      .        .00      .00     1.00      .00
    5.00  -999.00      .00      .00      .00     1.00
 
Number of cases read:  5    Number of cases listed:  5


Variable x is only needed temporarily, and should probably be discarded after running Jon's code.

p.s. - I wondered if I could use a scratch variable in place of Jon's x.  ANSWER:  No.  MRSETS requires a list of at least 2 standard variables.

 
 
Art Kendall wrote
" just set a variable to all sysmis values"

Would this approach work if user missing values were input.

[My soapbox about missing values being user missing if the user inputs them with sysmis reserved for when the software is unable to follow instructions. Maintaining this distinction user/system missing can be a great aid in validating/referencing/quality assurance.]
--
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: Creating set of variables with varying subscripts.

venkatesh gandi
A bunch of thanks to Bruce and Jon. The code helps me a lot and solved the problem.

And a special thanks to you Bruce for your detailed explanation and your effort. A lot of things i had learned by this post. Very interested to know about writing code using python :) . Can any one suggest the best resource to learn that one.

On Thu, Jul 21, 2016 at 7:54 PM, Bruce Weaver <[hidden email]> wrote:
Hi Art.  Jon included variable x in his example (shown below) because MRSETS
needs to have at least two variables listed on the /MCGROUP sub-command.  As
far as I can tell, all values of x have to be missing for MRSETS to work as
intended in this case.  But they can be either SYSMIS or user-defined
missing values.  For example:

* Modificiation of Jon's example.
data list free/q17.
begin data
1 2 1 3 5
end data.

* Add variable x, because MRSETS needs at least 2 variables listed.
IF ANY($casenum,1,3,5) x = -999.
* For Jon's solution to work, all values of x must be missing (I think).
MISSING VALUES x (-999).
MRSETS
  /MCGROUP NAME=$fred VARIABLES=q17 x
  /DISPLAY NAME=[$fred].

STATS MCSET CONVERT mcset=$fred varprefix=Q setname=newset.
LIST.

OUTPUT:

     q17        x     Q_01     Q_02     Q_03     Q_04

    1.00  -999.00     1.00      .00      .00      .00
    2.00      .        .00     1.00      .00      .00
    1.00  -999.00     1.00      .00      .00      .00
    3.00      .        .00      .00     1.00      .00
    5.00  -999.00      .00      .00      .00     1.00

Number of cases read:  5    Number of cases listed:  5


Variable x is only needed temporarily, and should probably be discarded
after running Jon's code.

p.s. - I wondered if I could use a scratch variable in place of Jon's x.
ANSWER:  No.  MRSETS requires a list of at least 2 standard variables.




Art Kendall wrote
> " just set a variable to all sysmis values"
>
> Would this approach work if user missing values were input.
>
> [My soapbox about missing values being user missing if the user inputs
> them with sysmis reserved for when the software is unable to follow
> instructions. Maintaining this distinction user/system missing can be a
> great aid in validating/referencing/quality assurance.]





-----
--
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/Creating-set-of-variables-with-varying-subscripts-tp5732781p5732803.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: Creating set of variables with varying subscripts.

David Marso
Administrator
Here is an absolutely simple way to do it ;-)

DATA LIST FREE /ID X.
BEGIN DATA
1 1
2 3
3 5
4 6
5 7
END DATA.

COMPUTE Y=X.
FORMATS ALL (F1).

CASESTOVARS ID=ID
     /INDEX=X
     /AUTOFIX=NO
     /VIND Root Y_
     /DROP Y.
LIST.

ID Y_1 Y_3 Y_5 Y_6 Y_7
 
 1  1   0   0   0   0
 2  0   1   0   0   0
 3  0   0   1   0   0
 4  0   0   0   1   0
 5  0   0   0   0   1
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?"