Multiple response several answers variable string and separated into different variable

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

Multiple response several answers variable string and separated into different variable

Javier Figueroa
This problem I had already raised with the difference that the codes were
one digit and I received your help, today I have the same and I have not
been able to modify the macro, they could help me with this.

I will be eternally grateful.

Sincerely,


This macro was the one that I used with success, thanks David Marso
excellent. Today I want to modify it to work with codes or two-digit
answers.

Here is a method which uses this principle but with a bit more flexibility.
DATA LIST  / a b c (3A10).
BEGIN DATA
1234      345621    345632
122       1234      12345678
END DATA.

DEFINE !parse_num (vars !CHAREND('/') /max !cmdend )
!IF (!HEAD(!vars) !NE '') !THEN
!LET !v=!HEAD(!vars) !LET !m = !HEAD(!max)
!LET !vs=!CONCAT(!v,'_','1 TO ',!v,'_',!m)
NUMERIC !vs (F1).
VECTOR !v = !vs .
LOOP #=1 TO !m.
IF CHAR.SUBSTR(!v,#,1) NE '' !v(#)=NUMBER(CHAR.SUBSTR(!v,#,1),F1).
END LOOP.

/*Recursively call macro to run through vars and max lists*/.
!parse_num vars=!TAIL(!vars) / max=!TAIL(!max).
!IFEND
!ENDDEFINE.

!parse_num vars=a b c / max=4 6 8 .
/* run the following after all other desired transformations are done /*.
EXECUTE.



Any comments, I thank you in advance.


Hello experts SPSS

Good morning, I hope that all their activities ARE realizadon with hits.

I need your help, I have a variable of type character with several response
options TWO digit every answer and are not separated by commas or by white,
now I need to transfer these responses to different variables, for example.
the string is called resp variabla and contine 0102030498, what I need is
to generate five variables with var1 = 1 data, var2 = 2, var3 = 3, var4 =
4, var5 = 98.

I found this macro is very good but I only work if the answers are
separated by commas or white, I could help to change this macro and use it.


--
Javier Figueroa
Procesamiento y Análisis de bases de datos
Cel: 5927-4748 / 4970-1940
Casa: 2289-0184

===================== 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: Multiple response several answers variable string and separated into different variable

David Marso
Administrator
You might want to post an example of what you are trying to parse and any
attempted modifications of the macro and their outcomes.   Do you understand
the macro or are you blindly copy/pasting?  How would you do it without a
macro ie simple syntax.


Javier Figueroa wrote

> This problem I had already raised with the difference that the codes were
> one digit and I received your help, today I have the same and I have not
> been able to modify the macro, they could help me with this.
>
> I will be eternally grateful.
>
> Sincerely,
>
>
> This macro was the one that I used with success, thanks David Marso
> excellent. Today I want to modify it to work with codes or two-digit
> answers.
>
> Here is a method which uses this principle but with a bit more
> flexibility.
> DATA LIST  / a b c (3A10).
> BEGIN DATA
> 1234      345621    345632
> 122       1234      12345678
> END DATA.
>
> DEFINE !parse_num (vars !CHAREND('/') /max !cmdend )
> !IF (!HEAD(!vars) !NE '') !THEN
> !LET !v=!HEAD(!vars) !LET !m = !HEAD(!max)
> !LET !vs=!CONCAT(!v,'_','1 TO ',!v,'_',!m)
> NUMERIC !vs (F1).
> VECTOR !v = !vs .
> LOOP #=1 TO !m.
> IF CHAR.SUBSTR(!v,#,1) NE '' !v(#)=NUMBER(CHAR.SUBSTR(!v,#,1),F1).
> END LOOP.
>
> /*Recursively call macro to run through vars and max lists*/.
> !parse_num vars=!TAIL(!vars) / max=!TAIL(!max).
> !IFEND
> !ENDDEFINE.
>
> !parse_num vars=a b c / max=4 6 8 .
> /* run the following after all other desired transformations are done /*.
> EXECUTE.
>
>
>
> Any comments, I thank you in advance.
>
>
> Hello experts SPSS
>
> Good morning, I hope that all their activities ARE realizadon with hits.
>
> I need your help, I have a variable of type character with several
> response
> options TWO digit every answer and are not separated by commas or by
> white,
> now I need to transfer these responses to different variables, for
> example.
> the string is called resp variabla and contine 0102030498, what I need is
> to generate five variables with var1 = 1 data, var2 = 2, var3 = 3, var4 =
> 4, var5 = 98.
>
> I found this macro is very good but I only work if the answers are
> separated by commas or white, I could help to change this macro and use
> it.
>
>
> --
>
> *Javier FigueroaProcesamiento y Análisis de bases de datos*
> *Cel: 5927-4748 / 4970-1940*
>
>
> *Casa: 2289-0184*
>
> =====================
> 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

Xx



-----
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?"
--
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
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: Multiple response several answers variable string and separated into different variable

Javier Figueroa
Thank you very much for your prompt response, David

the solution that you indicate if you identify the two-digit answers, but when you print them in the new variables, leave a blank variable between the possible answers, eg. 01020398 the result is 

var1 = 1, 
var2 =., 
Var3 = 2, 
var4 =., 
Var5 = 3, 
var6 =., 

how can I do to omit the blank variable and the answers are followed.

DATA LIST  / P2 P3 P4 (3A10).
BEGIN DATA
10203   030405     030405632 
010202 01020304 0102030405
END DATA.

DEFINE !parse_num (vars !CHAREND('/') /max !cmdend )
!IF (!HEAD(!vars) !NE '') !THEN
!LET !v=!HEAD(!vars) !LET !m = !HEAD(!max)
!LET !vs=!CONCAT(!v,'_','1 TO ',!v,'_',!m)
NUMERIC !vs (F2).
VECTOR !v = !vs.
LOOP #=1 TO !m BY 2.
IF CHAR.SUBSTR(!v,#,2) NE '' !v(#)=NUMBER(CHAR.SUBSTR(!v,#,2),F2).
END LOOP.

/*Recursively call macro to run through vars and max lists/*.
!parse_num vars=!TAIL(!vars) / max=!TAIL(!max).
!IFEND
!ENDDEFINE.

!parse_num vars=P2 P3 P4 / max=4 4 6.
/* run the following after all other desired transformations are done /*.
EXECUTE.



When I write code, I mean the possible answers.

thanks for your help,

ah, I apologize for sending this problem to personal emails,

2018-06-26 18:37 GMT-06:00 David Marso <[hidden email]>:
You might want to post an example of what you are trying to parse and any
attempted modifications of the macro and their outcomes.   Do you understand
the macro or are you blindly copy/pasting?  How would you do it without a
macro ie simple syntax.


Javier Figueroa wrote
> This problem I had already raised with the difference that the codes were
> one digit and I received your help, today I have the same and I have not
> been able to modify the macro, they could help me with this.
>
> I will be eternally grateful.
>
> Sincerely,
>
>
> This macro was the one that I used with success, thanks David Marso
> excellent. Today I want to modify it to work with codes or two-digit
> answers.
>
> Here is a method which uses this principle but with a bit more
> flexibility.
> DATA LIST  / a b c (3A10).
> BEGIN DATA
> 1234      345621    345632
> 122       1234      12345678
> END DATA.
>
> DEFINE !parse_num (vars !CHAREND('/') /max !cmdend )
> !IF (!HEAD(!vars) !NE '') !THEN
> !LET !v=!HEAD(!vars) !LET !m = !HEAD(!max)
> !LET !vs=!CONCAT(!v,'_','1 TO ',!v,'_',!m)
> NUMERIC !vs (F1).
> VECTOR !v = !vs .
> LOOP #=1 TO !m.
> IF CHAR.SUBSTR(!v,#,1) NE '' !v(#)=NUMBER(CHAR.SUBSTR(!v,#,1),F1).
> END LOOP.
>
> /*Recursively call macro to run through vars and max lists*/.
> !parse_num vars=!TAIL(!vars) / max=!TAIL(!max).
> !IFEND
> !ENDDEFINE.
>
> !parse_num vars=a b c / max=4 6 8 .
> /* run the following after all other desired transformations are done /*.
> EXECUTE.
>
>
>
> Any comments, I thank you in advance.
>
>
> Hello experts SPSS
>
> Good morning, I hope that all their activities ARE realizadon with hits.
>
> I need your help, I have a variable of type character with several
> response
> options TWO digit every answer and are not separated by commas or by
> white,
> now I need to transfer these responses to different variables, for
> example.
> the string is called resp variabla and contine 0102030498, what I need is
> to generate five variables with var1 = 1 data, var2 = 2, var3 = 3, var4 =
> 4, var5 = 98.
>
> I found this macro is very good but I only work if the answers are
> separated by commas or white, I could help to change this macro and use
> it.
>
>
> --
>
> *Javier FigueroaProcesamiento y Análisis de bases de datos*
> *Cel: 5927-4748 / 4970-1940*
>
>
> *Casa: 2289-0184*
>
> =====================
> 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

Xx



-----
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?"
--
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



--
Javier Figueroa
Procesamiento y Análisis de bases de datos
Cel: 5927-4748 / 4970-1940
Casa: 2289-0184

===================== 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: Multiple response several answers variable string and separated into different variable

David Marso
Administrator
LOOP #=1 TO !m BY 2.
IF CHAR.SUBSTR(!v,#,2) NE '' !v((#+1)/2)=NUMBER(CHAR.SUBSTR(!v,#,2),F2).
END LOOP.

Notice previous version stepped by 1 for both the vector index and the
string parse.
Now that we are stepping by 2 you need to modify the vector index
accordingly.

(1+1)/2=1,  (3+1)/2=2 etc...


Javier Figueroa wrote

> Thank you very much for your prompt response, David
>
> the solution that you indicate if you identify the two-digit answers, but
> when you print them in the new variables, leave a blank variable between
> the possible answers, eg. 01020398 the result is
>
> var1 = 1,
> var2 =.,
> Var3 = 2,
> var4 =.,
> Var5 = 3,
> var6 =.,
>
> how can I do to omit the blank variable and the answers are followed.
>
> DATA LIST  / P2 P3 P4 (3A10).
> BEGIN DATA
> 10203   030405     030405632
> 010202 01020304 0102030405
> END DATA.
>
> DEFINE !parse_num (vars !CHAREND('/') /max !cmdend )
> !IF (!HEAD(!vars) !NE '') !THEN
> !LET !v=!HEAD(!vars) !LET !m = !HEAD(!max)
> !LET !vs=!CONCAT(!v,'_','1 TO ',!v,'_',!m)
> NUMERIC !vs (F2).
> VECTOR !v = !vs.
> LOOP #=1 TO !m BY 2.
> IF CHAR.SUBSTR(!v,#,2) NE '' !v(#)=NUMBER(CHAR.SUBSTR(!v,#,2),F2).
> END LOOP.
>
> /*Recursively call macro to run through vars and max lists/*.
> !parse_num vars=!TAIL(!vars) / max=!TAIL(!max).
> !IFEND
> !ENDDEFINE.
>
> !parse_num vars=P2 P3 P4 / max=4 4 6.
> /* run the following after all other desired transformations are done /*.
> EXECUTE.
>
>
>
> When I write code, I mean the possible answers.
>
> thanks for your help,
>
> ah, I apologize for sending this problem to personal emails,
>
> 2018-06-26 18:37 GMT-06:00 David Marso &lt;

> david.marso@

> &gt;:
>
>> You might want to post an example of what you are trying to parse and any
>> attempted modifications of the macro and their outcomes.   Do you
>> understand
>> the macro or are you blindly copy/pasting?  How would you do it without a
>> macro ie simple syntax.
>>
>>
>> Javier Figueroa wrote
>> > This problem I had already raised with the difference that the codes
>> were
>> > one digit and I received your help, today I have the same and I have
>> not
>> > been able to modify the macro, they could help me with this.
>> >
>> > I will be eternally grateful.
>> >
>> > Sincerely,
>> >
>> >
>> > This macro was the one that I used with success, thanks David Marso
>> > excellent. Today I want to modify it to work with codes or two-digit
>> > answers.
>> >
>> > Here is a method which uses this principle but with a bit more
>> > flexibility.
>> > DATA LIST  / a b c (3A10).
>> > BEGIN DATA
>> > 1234      345621    345632
>> > 122       1234      12345678
>> > END DATA.
>> >
>> > DEFINE !parse_num (vars !CHAREND('/') /max !cmdend )
>> > !IF (!HEAD(!vars) !NE '') !THEN
>> > !LET !v=!HEAD(!vars) !LET !m = !HEAD(!max)
>> > !LET !vs=!CONCAT(!v,'_','1 TO ',!v,'_',!m)
>> > NUMERIC !vs (F1).
>> > VECTOR !v = !vs .
>> > LOOP #=1 TO !m.
>> > IF CHAR.SUBSTR(!v,#,1) NE '' !v(#)=NUMBER(CHAR.SUBSTR(!v,#,1),F1).
>> > END LOOP.
>> >
>> > /*Recursively call macro to run through vars and max lists*/.
>> > !parse_num vars=!TAIL(!vars) / max=!TAIL(!max).
>> > !IFEND
>> > !ENDDEFINE.
>> >
>> > !parse_num vars=a b c / max=4 6 8 .
>> > /* run the following after all other desired transformations are done
>> /*.
>> > EXECUTE.
>> >
>> >
>> >
>> > Any comments, I thank you in advance.
>> >
>> >
>> > Hello experts SPSS
>> >
>> > Good morning, I hope that all their activities ARE realizadon with
>> hits.
>> >
>> > I need your help, I have a variable of type character with several
>> > response
>> > options TWO digit every answer and are not separated by commas or by
>> > white,
>> > now I need to transfer these responses to different variables, for
>> > example.
>> > the string is called resp variabla and contine 0102030498, what I need
>> is
>> > to generate five variables with var1 = 1 data, var2 = 2, var3 = 3, var4
>> =
>> > 4, var5 = 98.
>> >
>> > I found this macro is very good but I only work if the answers are
>> > separated by commas or white, I could help to change this macro and use
>> > it.
>> >
>> >
>> > --
>> >
>> > *Javier FigueroaProcesamiento y Análisis de bases de datos*
>> > *Cel: 5927-4748 / 4970-1940*
>> >
>> >
>> > *Casa: 2289-0184*
>> >
>> > =====================
>> > 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
>>
>> Xx
>>
>>
>>
>> -----
>> 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?"
>> --
>> Sent from: http://spssx-discussion.1045642.n5.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
>>
>
>
>
> --
>
> *Javier FigueroaProcesamiento y Análisis de bases de datos*
> *Cel: 5927-4748 / 4970-1940*
>
>
> *Casa: 2289-0184*
>
> =====================
> 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?"
--
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
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: Multiple response several answers variable string and separated into different variable

Javier Figueroa
Thank you very much for your help, I think this macro is very useful and it will serve many people. Thank you. I just ran into a problem and solve it by increasing the number of possible answers, eg.

! parse_num vars = P2 P3 P4 P5A P6A P5B P6B P6C_1 P6C_2 P6C_3 P6C_4 P6C_5 P6C_6 P8 P12 P13 / max = 6 6 6 10 10 10 10 10 10 10 10 10 10 6 6 6.
/ * run the following after all other desired transformations are done / *.
EXECUTE.

in maximum of answers is 5 I have to double and put 10 if I want a maximum of 3 I have to put 6 and since they are two digits the numbers that must enter is an even number, it gives an error if they write an inpar number.



if this can be fixed, and leaving it standard would be excellent.

Thank you very much again, with this you solved a lot of work and I think that also many more people.

Sincerely,

2018-06-27 9:41 GMT-06:00 David Marso <[hidden email]>:
LOOP #=1 TO !m BY 2.
IF CHAR.SUBSTR(!v,#,2) NE '' !v((#+1)/2)=NUMBER(CHAR.SUBSTR(!v,#,2),F2).
END LOOP.

Notice previous version stepped by 1 for both the vector index and the
string parse.
Now that we are stepping by 2 you need to modify the vector index
accordingly.

(1+1)/2=1,  (3+1)/2=2 etc...


Javier Figueroa wrote
> Thank you very much for your prompt response, David
>
> the solution that you indicate if you identify the two-digit answers, but
> when you print them in the new variables, leave a blank variable between
> the possible answers, eg. 01020398 the result is
>
> var1 = 1,
> var2 =.,
> Var3 = 2,
> var4 =.,
> Var5 = 3,
> var6 =.,
>
> how can I do to omit the blank variable and the answers are followed.
>
> DATA LIST  / P2 P3 P4 (3A10).
> BEGIN DATA
> 10203   030405     030405632
> 010202 01020304 0102030405
> END DATA.
>
> DEFINE !parse_num (vars !CHAREND('/') /max !cmdend )
> !IF (!HEAD(!vars) !NE '') !THEN
> !LET !v=!HEAD(!vars) !LET !m = !HEAD(!max)
> !LET !vs=!CONCAT(!v,'_','1 TO ',!v,'_',!m)
> NUMERIC !vs (F2).
> VECTOR !v = !vs.
> LOOP #=1 TO !m BY 2.
> IF CHAR.SUBSTR(!v,#,2) NE '' !v(#)=NUMBER(CHAR.SUBSTR(!v,#,2),F2).
> END LOOP.
>
> /*Recursively call macro to run through vars and max lists/*.
> !parse_num vars=!TAIL(!vars) / max=!TAIL(!max).
> !IFEND
> !ENDDEFINE.
>
> !parse_num vars=P2 P3 P4 / max=4 4 6.
> /* run the following after all other desired transformations are done /*.
> EXECUTE.
>
>
>
> When I write code, I mean the possible answers.
>
> thanks for your help,
>
> ah, I apologize for sending this problem to personal emails,
>
> 2018-06-26 18:37 GMT-06:00 David Marso &lt;

> david.marso@

> &gt;:
>
>> You might want to post an example of what you are trying to parse and any
>> attempted modifications of the macro and their outcomes.   Do you
>> understand
>> the macro or are you blindly copy/pasting?  How would you do it without a
>> macro ie simple syntax.
>>
>>
>> Javier Figueroa wrote
>> > This problem I had already raised with the difference that the codes
>> were
>> > one digit and I received your help, today I have the same and I have
>> not
>> > been able to modify the macro, they could help me with this.
>> >
>> > I will be eternally grateful.
>> >
>> > Sincerely,
>> >
>> >
>> > This macro was the one that I used with success, thanks David Marso
>> > excellent. Today I want to modify it to work with codes or two-digit
>> > answers.
>> >
>> > Here is a method which uses this principle but with a bit more
>> > flexibility.
>> > DATA LIST  / a b c (3A10).
>> > BEGIN DATA
>> > 1234      345621    345632
>> > 122       1234      12345678
>> > END DATA.
>> >
>> > DEFINE !parse_num (vars !CHAREND('/') /max !cmdend )
>> > !IF (!HEAD(!vars) !NE '') !THEN
>> > !LET !v=!HEAD(!vars) !LET !m = !HEAD(!max)
>> > !LET !vs=!CONCAT(!v,'_','1 TO ',!v,'_',!m)
>> > NUMERIC !vs (F1).
>> > VECTOR !v = !vs .
>> > LOOP #=1 TO !m.
>> > IF CHAR.SUBSTR(!v,#,1) NE '' !v(#)=NUMBER(CHAR.SUBSTR(!v,#,1),F1).
>> > END LOOP.
>> >
>> > /*Recursively call macro to run through vars and max lists*/.
>> > !parse_num vars=!TAIL(!vars) / max=!TAIL(!max).
>> > !IFEND
>> > !ENDDEFINE.
>> >
>> > !parse_num vars=a b c / max=4 6 8 .
>> > /* run the following after all other desired transformations are done
>> /*.
>> > EXECUTE.
>> >
>> >
>> >
>> > Any comments, I thank you in advance.
>> >
>> >
>> > Hello experts SPSS
>> >
>> > Good morning, I hope that all their activities ARE realizadon with
>> hits.
>> >
>> > I need your help, I have a variable of type character with several
>> > response
>> > options TWO digit every answer and are not separated by commas or by
>> > white,
>> > now I need to transfer these responses to different variables, for
>> > example.
>> > the string is called resp variabla and contine 0102030498, what I need
>> is
>> > to generate five variables with var1 = 1 data, var2 = 2, var3 = 3, var4
>> =
>> > 4, var5 = 98.
>> >
>> > I found this macro is very good but I only work if the answers are
>> > separated by commas or white, I could help to change this macro and use
>> > it.
>> >
>> >
>> > --
>> >
>> > *Javier FigueroaProcesamiento y Análisis de bases de datos*
>> > *Cel: 5927-4748 / 4970-1940*
>> >
>> >
>> > *Casa: 2289-0184*
>> >
>> > =====================
>> > 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
>>
>> Xx
>>
>>
>>
>> -----
>> 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?"
>> --
>> Sent from: http://spssx-discussion.1045642.n5.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
>>
>
>
>
> --
>
> *Javier FigueroaProcesamiento y Análisis de bases de datos*
> *Cel: 5927-4748 / 4970-1940*
>
>
> *Casa: 2289-0184*
>
> =====================
> 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?"
--
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



--
Javier Figueroa
Procesamiento y Análisis de bases de datos
Cel: 5927-4748 / 4970-1940
Casa: 2289-0184

===================== 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: Multiple response several answers variable string and separated into different variable

David Marso
Administrator
Much easier to do it as follows.

LOOP #=1 TO !m *2 BY 2.
IF CHAR.SUBSTR(!v,#,2) NE '' !v(#)=NUMBER(CHAR.SUBSTR(!v,#,2),F2).
END LOOP.

On Wed, Jun 27, 2018, 1:00 PM Javier Figueroa <[hidden email]> wrote:
Thank you very much for your help, I think this macro is very useful and it will serve many people. Thank you. I just ran into a problem and solve it by increasing the number of possible answers, eg.

! parse_num vars = P2 P3 P4 P5A P6A P5B P6B P6C_1 P6C_2 P6C_3 P6C_4 P6C_5 P6C_6 P8 P12 P13 / max = 6 6 6 10 10 10 10 10 10 10 10 10 10 6 6 6.
/ * run the following after all other desired transformations are done / *.
EXECUTE.

in maximum of answers is 5 I have to double and put 10 if I want a maximum of 3 I have to put 6 and since they are two digits the numbers that must enter is an even number, it gives an error if they write an inpar number.



if this can be fixed, and leaving it standard would be excellent.

Thank you very much again, with this you solved a lot of work and I think that also many more people.

Sincerely,

2018-06-27 9:41 GMT-06:00 David Marso <[hidden email]>:
LOOP #=1 TO !m BY 2.
IF CHAR.SUBSTR(!v,#,2) NE '' !v((#+1)/2)=NUMBER(CHAR.SUBSTR(!v,#,2),F2).
END LOOP.

Notice previous version stepped by 1 for both the vector index and the
string parse.
Now that we are stepping by 2 you need to modify the vector index
accordingly.

(1+1)/2=1,  (3+1)/2=2 etc...


Javier Figueroa wrote
> Thank you very much for your prompt response, David
>
> the solution that you indicate if you identify the two-digit answers, but
> when you print them in the new variables, leave a blank variable between
> the possible answers, eg. 01020398 the result is
>
> var1 = 1,
> var2 =.,
> Var3 = 2,
> var4 =.,
> Var5 = 3,
> var6 =.,
>
> how can I do to omit the blank variable and the answers are followed.
>
> DATA LIST  / P2 P3 P4 (3A10).
> BEGIN DATA
> 10203   030405     030405632
> 010202 01020304 0102030405
> END DATA.
>
> DEFINE !parse_num (vars !CHAREND('/') /max !cmdend )
> !IF (!HEAD(!vars) !NE '') !THEN
> !LET !v=!HEAD(!vars) !LET !m = !HEAD(!max)
> !LET !vs=!CONCAT(!v,'_','1 TO ',!v,'_',!m)
> NUMERIC !vs (F2).
> VECTOR !v = !vs.
> LOOP #=1 TO !m BY 2.
> IF CHAR.SUBSTR(!v,#,2) NE '' !v(#)=NUMBER(CHAR.SUBSTR(!v,#,2),F2).
> END LOOP.
>
> /*Recursively call macro to run through vars and max lists/*.
> !parse_num vars=!TAIL(!vars) / max=!TAIL(!max).
> !IFEND
> !ENDDEFINE.
>
> !parse_num vars=P2 P3 P4 / max=4 4 6.
> /* run the following after all other desired transformations are done /*.
> EXECUTE.
>
>
>
> When I write code, I mean the possible answers.
>
> thanks for your help,
>
> ah, I apologize for sending this problem to personal emails,
>
> 2018-06-26 18:37 GMT-06:00 David Marso &lt;

> david.marso@

> &gt;:
>
>> You might want to post an example of what you are trying to parse and any
>> attempted modifications of the macro and their outcomes.   Do you
>> understand
>> the macro or are you blindly copy/pasting?  How would you do it without a
>> macro ie simple syntax.
>>
>>
>> Javier Figueroa wrote
>> > This problem I had already raised with the difference that the codes
>> were
>> > one digit and I received your help, today I have the same and I have
>> not
>> > been able to modify the macro, they could help me with this.
>> >
>> > I will be eternally grateful.
>> >
>> > Sincerely,
>> >
>> >
>> > This macro was the one that I used with success, thanks David Marso
>> > excellent. Today I want to modify it to work with codes or two-digit
>> > answers.
>> >
>> > Here is a method which uses this principle but with a bit more
>> > flexibility.
>> > DATA LIST  / a b c (3A10).
>> > BEGIN DATA
>> > 1234      345621    345632
>> > 122       1234      12345678
>> > END DATA.
>> >
>> > DEFINE !parse_num (vars !CHAREND('/') /max !cmdend )
>> > !IF (!HEAD(!vars) !NE '') !THEN
>> > !LET !v=!HEAD(!vars) !LET !m = !HEAD(!max)
>> > !LET !vs=!CONCAT(!v,'_','1 TO ',!v,'_',!m)
>> > NUMERIC !vs (F1).
>> > VECTOR !v = !vs .
>> > LOOP #=1 TO !m.
>> > IF CHAR.SUBSTR(!v,#,1) NE '' !v(#)=NUMBER(CHAR.SUBSTR(!v,#,1),F1).
>> > END LOOP.
>> >
>> > /*Recursively call macro to run through vars and max lists*/.
>> > !parse_num vars=!TAIL(!vars) / max=!TAIL(!max).
>> > !IFEND
>> > !ENDDEFINE.
>> >
>> > !parse_num vars=a b c / max=4 6 8 .
>> > /* run the following after all other desired transformations are done
>> /*.
>> > EXECUTE.
>> >
>> >
>> >
>> > Any comments, I thank you in advance.
>> >
>> >
>> > Hello experts SPSS
>> >
>> > Good morning, I hope that all their activities ARE realizadon with
>> hits.
>> >
>> > I need your help, I have a variable of type character with several
>> > response
>> > options TWO digit every answer and are not separated by commas or by
>> > white,
>> > now I need to transfer these responses to different variables, for
>> > example.
>> > the string is called resp variabla and contine 0102030498, what I need
>> is
>> > to generate five variables with var1 = 1 data, var2 = 2, var3 = 3, var4
>> =
>> > 4, var5 = 98.
>> >
>> > I found this macro is very good but I only work if the answers are
>> > separated by commas or white, I could help to change this macro and use
>> > it.
>> >
>> >
>> > --
>> >
>> > *Javier FigueroaProcesamiento y Análisis de bases de datos*
>> > *Cel: 5927-4748 / 4970-1940*
>> >
>> >
>> > *Casa: 2289-0184*
>> >
>> > =====================
>> > 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
>>
>> Xx
>>
>>
>>
>> -----
>> 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?"
>> --
>> Sent from: http://spssx-discussion.1045642.n5.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
>>
>
>
>
> --
>
> *Javier FigueroaProcesamiento y Análisis de bases de datos*
> *Cel: 5927-4748 / 4970-1940*
>
>
> *Casa: 2289-0184*
>
> =====================
> 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?"
--
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



--
Javier Figueroa
Procesamiento y Análisis de bases de datos
Cel: 5927-4748 / 4970-1940
Casa: 2289-0184

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