Creating multiple variables with Do Repeat?

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

Creating multiple variables with Do Repeat?

Jeff6610

 

I have several numeric variables, e.g., Age, Sex, Educ, etc. etc..

 

I want to create string variables with the same names with a Suffix on the end: e.g., AgeX, SexX, EducX perhaps with format (A10).

 

Can this be done with a Do Repeat Loop  so I can just add a long list of variables on the first line?

 

…something like this?

 

Do Repeat w = Age Sex Educ .

{create string variable w + “X” (A10).}

End repeat.

 

 

===================== 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 multiple variables with Do Repeat?

David Marso
Administrator
Create a Macro. Read up on !CONCAT and !DO !DOEND in the context of DEFINE
!ENDDEFINE.

DEFINE !MyConcat (List !CMDEND)
!DO !v !IN (!List)
STRING !CONCAT(!v,"X"),(A1000).
COMPUTE !CONCAT(!v,"X")=STRING(!F(!v),F?.?).
!DOEND
!ENDDEFINE.



-----
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: Creating multiple variables with Do Repeat?

Jeff6610
Excellent ! Got it working quickly.

Quick follow-ups:

1) Is there a good on-line source you recommend for me to read more about
Macros? I've read a bit previously, but could learn more.

2) Is there a way that I can create a list of variables in my syntax file
that I could use in this macro and then use again in another macro?

E.g., instead of:   !MyConcat  MyVar1 MyVar2 MyVar3 .  to run the macro
below,

Do something like this:
!MyConcat MyPreviouslyStoredListOfVariables .

Thanks in advance.

Jeff



-----Original Message-----
From: SPSSX(r) Discussion <[hidden email]> On Behalf Of David
Marso
Sent: Friday, 18 May 2018 12:11 AM
To: [hidden email]
Subject: Re: Creating multiple variables with Do Repeat?

Create a Macro. Read up on !CONCAT and !DO !DOEND in the context of DEFINE
!ENDDEFINE.

DEFINE !MyConcat (List !CMDEND)
!DO !v !IN (!List)
STRING !CONCAT(!v,"X"),(A1000).
COMPUTE !CONCAT(!v,"X")=STRING(!F(!v),F?.?).
!DOEND
!ENDDEFINE.



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

=====================
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 multiple variables with Do Repeat?

Jon Peck
You might be interested in the SPSSINC SELECT VARIABLES extension command.  It creates a macro listing variables select by the metadata such as patterns in names, type, measurement level etc.  that macro could be used in this one or any other.  It appears on the Utilities menu if installed.  If not, you can add it from the Extensions or Utilities menu.

On Thu, May 17, 2018 at 1:35 PM Jeff <[hidden email]> wrote:
Excellent ! Got it working quickly.

Quick follow-ups:

1) Is there a good on-line source you recommend for me to read more about
Macros? I've read a bit previously, but could learn more.

2) Is there a way that I can create a list of variables in my syntax file
that I could use in this macro and then use again in another macro?

E.g., instead of:   !MyConcat  MyVar1 MyVar2 MyVar3 .  to run the macro
below,

Do something like this:
!MyConcat MyPreviouslyStoredListOfVariables .

Thanks in advance.

Jeff



-----Original Message-----
From: SPSSX(r) Discussion <[hidden email]> On Behalf Of David
Marso
Sent: Friday, 18 May 2018 12:11 AM
To: [hidden email]
Subject: Re: Creating multiple variables with Do Repeat?

Create a Macro. Read up on !CONCAT and !DO !DOEND in the context of DEFINE
!ENDDEFINE.

DEFINE !MyConcat (List !CMDEND)
!DO !v !IN (!List)
STRING !CONCAT(!v,"X"),(A1000).
COMPUTE !CONCAT(!v,"X")=STRING(!F(!v),F?.?).
!DOEND
!ENDDEFINE.



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

=====================
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 multiple variables with Do Repeat?

Jeff6610

 

Unsure that I’m following here.

 

In Utilities, “Use Variable Sets” seems to only show/hide selected variables in the editor, but doesn’t permit me to work with the sets in syntax – perhaps I’m doing something wrong?

 

In Extensions, “Extension Hub” > when I search for SPSSINC SELECT VARIABLES – nothing is found.

 

I’m likely not needing anything complex. Just a way to have 2 or more different lists of variable names that I could use in different macros.

 

e.g.,

 

MyPreviouslyStoredListOfVariablesFULL = V1 V2 V3 V4

MyPreviouslyStoredListOfVariablesPartial = V1 V2 V3 .

 

 

From: Jon Peck <[hidden email]>
Sent: Friday, 18 May 2018 5:39 AM
To: Jeff <[hidden email]>; [hidden email]
Subject: Re: [SPSSX-L] Creating multiple variables with Do Repeat?

 

You might be interested in the SPSSINC SELECT VARIABLES extension command.  It creates a macro listing variables select by the metadata such as patterns in names, type, measurement level etc.  that macro could be used in this one or any other.  It appears on the Utilities menu if installed.  If not, you can add it from the Extensions or Utilities menu.

 

On Thu, May 17, 2018 at 1:35 PM Jeff <[hidden email]> wrote:

Excellent ! Got it working quickly.

Quick follow-ups:

1) Is there a good on-line source you recommend for me to read more about
Macros? I've read a bit previously, but could learn more.

2) Is there a way that I can create a list of variables in my syntax file
that I could use in this macro and then use again in another macro?

E.g., instead of:   !MyConcat  MyVar1 MyVar2 MyVar3 .  to run the macro
below,

Do something like this:
!MyConcat MyPreviouslyStoredListOfVariables .

Thanks in advance.

Jeff



-----Original Message-----
From: SPSSX(r) Discussion <[hidden email]> On Behalf Of David
Marso
Sent: Friday, 18 May 2018 12:11 AM
To: [hidden email]
Subject: Re: Creating multiple variables with Do Repeat?

Create a Macro. Read up on !CONCAT and !DO !DOEND in the context of DEFINE
!ENDDEFINE.

DEFINE !MyConcat (List !CMDEND)
!DO !v !IN (!List)
STRING !CONCAT(!v,"X"),(A1000).
COMPUTE !CONCAT(!v,"X")=STRING(!F(!v),F?.?).
!DOEND
!ENDDEFINE.



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

=====================
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 multiple variables with Do Repeat?

Bruce Weaver
Administrator
In reply to this post by Jeff6610
Jeff, the first macro example in FM entry for DEFINE-!ENDDEFINE shows how to
use a macro for a list of variables.  

* Macro without arguments: Specify a group of variables.
 
DEFINE sesvars ()
   age sex educ religion
!ENDDEFINE.
 
FREQUENCIES VARIABLES=sesvars.

Source:
https://www.ibm.com/support/knowledgecenter/en/SSLVMB_25.0.0/statistics_reference_project_ddita/spss/base/syn_define_examples.html



Jeff-2 wrote

> Excellent ! Got it working quickly.
>
> Quick follow-ups:
>
> 1) Is there a good on-line source you recommend for me to read more about
> Macros? I've read a bit previously, but could learn more.
>
> 2) Is there a way that I can create a list of variables in my syntax file
> that I could use in this macro and then use again in another macro?
>
> E.g., instead of:   !MyConcat  MyVar1 MyVar2 MyVar3 .  to run the macro
> below,
>
> Do something like this:
> !MyConcat MyPreviouslyStoredListOfVariables .
>
> Thanks in advance.
>
> Jeff
>
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion &lt;

> SPSSX-L@.UGA

> &gt; On Behalf Of David
> Marso
> Sent: Friday, 18 May 2018 12:11 AM
> To:

> SPSSX-L@.UGA

> Subject: Re: Creating multiple variables with Do Repeat?
>
> Create a Macro. Read up on !CONCAT and !DO !DOEND in the context of DEFINE
> !ENDDEFINE.
>
> DEFINE !MyConcat (List !CMDEND)
> !DO !v !IN (!List)
> STRING !CONCAT(!v,"X"),(A1000).
> COMPUTE !CONCAT(!v,"X")=STRING(!F(!v),F?.?).
> !DOEND
> !ENDDEFINE.
>
>
>
> -----
> 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
>
> =====================
> 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.

--
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
--
Bruce Weaver
bweaver@lakeheadu.ca
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.
Reply | Threaded
Open this post in threaded view
|

Re: Creating multiple variables with Do Repeat?

Jeff6610
Yup. Exactly what I needed.  ...works perfectly.

Thanks

Jeff



-----Original Message-----
From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Bruce
Weaver
Sent: Friday, 18 May 2018 7:02 AM
To: [hidden email]
Subject: Re: Creating multiple variables with Do Repeat?

Jeff, the first macro example in FM entry for DEFINE-!ENDDEFINE shows how to
use a macro for a list of variables.  

* Macro without arguments: Specify a group of variables.
 
DEFINE sesvars ()
   age sex educ religion
!ENDDEFINE.
 
FREQUENCIES VARIABLES=sesvars.

Source:
https://www.ibm.com/support/knowledgecenter/en/SSLVMB_25.0.0/statistics_refe
rence_project_ddita/spss/base/syn_define_examples.html



Jeff-2 wrote

> Excellent ! Got it working quickly.
>
> Quick follow-ups:
>
> 1) Is there a good on-line source you recommend for me to read more
> about Macros? I've read a bit previously, but could learn more.
>
> 2) Is there a way that I can create a list of variables in my syntax
> file that I could use in this macro and then use again in another macro?
>
> E.g., instead of:   !MyConcat  MyVar1 MyVar2 MyVar3 .  to run the macro
> below,
>
> Do something like this:
> !MyConcat MyPreviouslyStoredListOfVariables .
>
> Thanks in advance.
>
> Jeff
>
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion &lt;

> SPSSX-L@.UGA

> &gt; On Behalf Of David
> Marso
> Sent: Friday, 18 May 2018 12:11 AM
> To:

> SPSSX-L@.UGA

> Subject: Re: Creating multiple variables with Do Repeat?
>
> Create a Macro. Read up on !CONCAT and !DO !DOEND in the context of
> DEFINE !ENDDEFINE.
>
> DEFINE !MyConcat (List !CMDEND)
> !DO !v !IN (!List)
> STRING !CONCAT(!v,"X"),(A1000).
> COMPUTE !CONCAT(!v,"X")=STRING(!F(!v),F?.?).
> !DOEND
> !ENDDEFINE.
>
>
>
> -----
> 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
>
> =====================
> 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.

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

=====================
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 multiple variables with Do Repeat?

David Marso
Administrator
In reply to this post by Jeff6610
http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=search_page&node=1068821&query=ENDDEFINE&days=0


Jeff-2 wrote

> Excellent ! Got it working quickly.
>
> Quick follow-ups:
>
> 1) Is there a good on-line source you recommend for me to read more about
> Macros? I've read a bit previously, but could learn more.
>
> 2) Is there a way that I can create a list of variables in my syntax file
> that I could use in this macro and then use again in another macro?
>
> E.g., instead of:   !MyConcat  MyVar1 MyVar2 MyVar3 .  to run the macro
> below,
>
> Do something like this:
> !MyConcat MyPreviouslyStoredListOfVariables .
>
> Thanks in advance.
>
> Jeff
>
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion &lt;

> SPSSX-L@.UGA

> &gt; On Behalf Of David
> Marso
> Sent: Friday, 18 May 2018 12:11 AM
> To:

> SPSSX-L@.UGA

> Subject: Re: Creating multiple variables with Do Repeat?
>
> Create a Macro. Read up on !CONCAT and !DO !DOEND in the context of DEFINE
> !ENDDEFINE.
>
> DEFINE !MyConcat (List !CMDEND)
> !DO !v !IN (!List)
> STRING !CONCAT(!v,"X"),(A1000).
> COMPUTE !CONCAT(!v,"X")=STRING(!F(!v),F?.?).
> !DOEND
> !ENDDEFINE.
>
>
>
> -----
> 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
>
> =====================
> 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: Creating multiple variables with Do Repeat?

Art Kendall
In reply to this post by Jeff6610
One way on a PC to get  a list of variables from an earlier point in a syntax
file is to
(1) scroll to the previous occurrence of the list.
(2) highlight the list
(3) hold the control shift and hit the "C" key.
(4) scroll to where you want the list
(5) hold the control shift and hit the "V" key.



-----
Art Kendall
Social Research Consultants
--
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
Art Kendall
Social Research Consultants