Macro question - loop!?

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

Macro question - loop!?

ksven
Hi there -
I am going crazy over something that should be easy to do.
I want to run correlations (or any other statistical procedure, incl frequencies) for different unique sub-groups. These groups are defined with 4 distinct variables, i.e. group1 - group4, with "1" identifying group members.

One option would be:

temporary.
sel if (group=1).
correlate x with y.
run.

I want do create a macro that "loops" through the four grouping variables and each time outputs the correlations.
This does not work with do repeat (only for transform commands) - I tried with !do ... !in and different statements trying to set the group variables to "1" but without success.

Any help is appreciated!!!




Reply | Threaded
Open this post in threaded view
|

Re: Macro question - loop!?

Bruce Weaver
Administrator
ksven wrote
Hi there -
I am going crazy over something that should be easy to do.
I want to run correlations (or any other statistical procedure, incl frequencies) for different unique sub-groups. These groups are defined with 4 distinct variables, i.e. group1 - group4, with "1" identifying group members.

One option would be:

temporary.
sel if (group=1).
correlate x with y.
run.

I want do create a macro that "loops" through the four grouping variables and each time outputs the correlations.
This does not work with do repeat (only for transform commands) - I tried with !do ... !in and different statements trying to set the group variables to "1" but without success.

Any help is appreciated!!!
It's not clear to me if you have 4 variables (columns) to indicate group membership, or ONE variable with 4 distinct values.  If the latter, just use SPLIT FILE.  E.g.,

sort cases by group.
SPLIT FILE by group.
correlate x with y.
SPLIT FILE OFF.

--
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: Macro question - loop!?

ksven
Hi Bruce -
thanks for your e-mail. I have four variables (columns) - split file does not work unfortunately

"It's not clear to me if you have 4 variables (columns) to indicate group membership, or ONE variable with 4 distinct values.  If the latter, just use SPLIT FILE.  E.g.,"
Reply | Threaded
Open this post in threaded view
|

Re: Macro question - loop!?

Jon K Peck

You can have up to eight split variables, so what doesn't work here?  The data, of course, have to be sorted appropriately.

Jon Peck
SPSS, an IBM Company
[hidden email]
312-651-3435



From: ksven <[hidden email]>
To: [hidden email]
Date: 02/22/2010 07:01 PM
Subject: Re: [SPSSX-L] Macro question - loop!?
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Hi Bruce -
thanks for your e-mail. I have four variables (columns) - split file does
not work unfortunately

"It's not clear to me if you have 4 variables (columns) to indicate group
membership, or ONE variable with 4 distinct values.  If the latter, just use
SPLIT FILE.  E.g.,"

--
View this message in context:
http://old.nabble.com/Macro-question---loop%21--tp27695044p27695192.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


Reply | Threaded
Open this post in threaded view
|

Re: Macro question - loop!?

Bruce Weaver
Administrator
Good catch, Jon.  SPLIT FILE will work, even if it is 4 indicator variables for group.  That didn't occur to me when I wrote my earlier reply, because I think of multiple split variables as giving you factorial combinations of variables (which they do).  I didn't get as far as recognizing that 4 indicator variables for group membership (G1, G2, G3, and G4, or whatever) yield only 4 combinations (not 16).  I.e.,

G1 G2 G3 G4
 1  0  0  0    - Group 1
 0  1  0  0    - Group 2
 0  0  1  0    - Group 3
 0  0  0  1    - Group 4

So the following should work.

sort cases by G1 G2 G3 G4 (d).
split file by G1 G2 G3 G4 .
correlate x with y.
split file off.

If the coding is 1-2 instead of 1-0, sort cases in ascending order rather than descending.


Jon K Peck wrote
You can have up to eight split variables, so what doesn't work here?  The
data, of course, have to be sorted appropriately.

Jon Peck
SPSS, an IBM Company
peck@us.ibm.com
312-651-3435



From:
ksven <svenklingemann@GMAIL.COM>
To:
SPSSX-L@LISTSERV.UGA.EDU
Date:
02/22/2010 07:01 PM
Subject:
Re: [SPSSX-L] Macro question - loop!?
Sent by:
"SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>



Hi Bruce -
thanks for your e-mail. I have four variables (columns) - split file does
not work unfortunately

"It's not clear to me if you have 4 variables (columns) to indicate group
membership, or ONE variable with 4 distinct values.  If the latter, just
use
SPLIT FILE.  E.g.,"

--
View this message in context:
http://old.nabble.com/Macro-question---loop%21--tp27695044p27695192.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (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: Macro question - loop!?

Florio Arguillas
In reply to this post by ksven
If an observation can belong to several groups, you can try this alternative.

DEFINE !mygroup (!pos !tokens(4)).
!do !grp !in (!1).
temporary.
select if (!grp=1).
fre !grp.
!doend.
!ENDDEFINE.
!mygroup group1 group2 group3 group4.


At 04:44 PM 2/22/2010, ksven wrote:

>Hi there -
>I am going crazy over something that should be easy to do.
>I want to run correlations (or any other statistical procedure, incl
>frequencies) for different unique sub-groups. These groups are defined with
>4 distinct variables, i.e. group1 - group4, with "1" identifying group
>members.
>
>One option would be:
>
>temporary.
>sel if (group=1).
>correlate x with y.
>run.
>
>I want do create a macro that "loops" through the four grouping variables
>and each time outputs the correlations.
>This does not work with do repeat (only for transform commands) - I tried
>with !do ... !in and different statements trying to set the group variables
>to "1" but without success.
>
>Any help is appreciated!!!
>
>
>
>
>
>--
>View this message in context:
>http://old.nabble.com/Macro-question---loop%21--tp27695044p27695044.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: Macro question - loop!?

ksven
In reply to this post by Bruce Weaver
Thanks. This is indeed going to work if you do not have overlapping group membership - which I have.
In that case I would get all combinations across groups, most of which I would not be interested in.
Best,
Sven


Bruce Weaver wrote
Good catch, Jon.  SPLIT FILE will work, even if it is 4 indicator variables for group.  That didn't occur to me when I wrote my earlier reply, because I think of multiple split variables as giving you factorial combinations of variables (which they do).  I didn't get as far as recognizing that 4 indicator variables for group membership (G1, G2, G3, and G4, or whatever) yield only 4 combinations (not 16).  I.e.,

G1 G2 G3 G4
 1  0  0  0    - Group 1
 0  1  0  0    - Group 2
 0  0  1  0    - Group 3
 0  0  0  1    - Group 4

So the following should work.

sort cases by G1 G2 G3 G4 (d).
split file by G1 G2 G3 G4 .
correlate x with y.
split file off.

If the coding is 1-2 instead of 1-0, sort cases in ascending order rather than descending.


Jon K Peck wrote
You can have up to eight split variables, so what doesn't work here?  The
data, of course, have to be sorted appropriately.

Jon Peck
SPSS, an IBM Company
peck@us.ibm.com
312-651-3435



From:
ksven <svenklingemann@GMAIL.COM>
To:
SPSSX-L@LISTSERV.UGA.EDU
Date:
02/22/2010 07:01 PM
Subject:
Re: [SPSSX-L] Macro question - loop!?
Sent by:
"SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>



Hi Bruce -
thanks for your e-mail. I have four variables (columns) - split file does
not work unfortunately

"It's not clear to me if you have 4 variables (columns) to indicate group
membership, or ONE variable with 4 distinct values.  If the latter, just
use
SPLIT FILE.  E.g.,"

--
View this message in context:
http://old.nabble.com/Macro-question---loop%21--tp27695044p27695192.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (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: Macro question - loop!?

ksven
In reply to this post by Florio Arguillas
Hi Florio -
this is exactly what I was looking for. I has tried similar syntax but it did not work for me.
Could you explain the  
 "(!1)" part of the syntax to me?

This is what I had that did not work:

define !recode (vname=!cmdend)
!DO !cnt !IN (!vname)
temporary.
select if (!vname=1).
freq var gender.
!DOEND
execute.
!enddefine.

!recode vname=group1 group2 group3 group4.

Best,
Sven



Florio Arguillas wrote
If an observation can belong to several groups, you can try this alternative.

DEFINE !mygroup (!pos !tokens(4)).
!do !grp !in (!1).
temporary.
select if (!grp=1).
fre !grp.
!doend.
!ENDDEFINE.
!mygroup group1 group2 group3 group4.


At 04:44 PM 2/22/2010, ksven wrote:
>Hi there -
>I am going crazy over something that should be easy to do.
>I want to run correlations (or any other statistical procedure, incl
>frequencies) for different unique sub-groups. These groups are defined with
>4 distinct variables, i.e. group1 - group4, with "1" identifying group
>members.
>
>One option would be:
>
>temporary.
>sel if (group=1).
>correlate x with y.
>run.
>
>I want do create a macro that "loops" through the four grouping variables
>and each time outputs the correlations.
>This does not work with do repeat (only for transform commands) - I tried
>with !do ... !in and different statements trying to set the group variables
>to "1" but without success.
>
>Any help is appreciated!!!
>
>
>
>
>
>--
>View this message in context:
>http://old.nabble.com/Macro-question---loop%21--tp27695044p27695044.html
>Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
>=====================
>To manage your subscription to SPSSX-L, send a message to
>LISTSERV@LISTSERV.UGA.EDU (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@LISTSERV.UGA.EDU (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: Macro question - loop!?

Bruce Weaver
Administrator
ksven wrote
Hi Florio -
this is exactly what I was looking for. I has tried similar syntax but it did not work for me.
Could you explain the  
 "(!1)" part of the syntax to me?

This is what I had that did not work:

define !recode (vname=!cmdend)
!DO !cnt !IN (!vname)
temporary.
select if (!vname=1).
freq var gender.
!DOEND
execute.
!enddefine.

!recode vname=group1 group2 group3 group4.

Best,
Sven
To debug a macro, set MPRINT to ON before running it.  I.e.,

set mprint on.
!recode vname=group1 group2 group3 group4.
set mprint off.

I think in your case, you need to change !vname to !cnt in this line:

select if (!vname=1).

Also, I think you can remove the execute.

--
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: Macro question - loop!?

ksven
Yes - both corrections are correct. I usually do use the set mprint=on, but it often does not tell you what
to do - just that it's wrong!
:-)
S.


Bruce Weaver wrote
ksven wrote
Hi Florio -
this is exactly what I was looking for. I has tried similar syntax but it did not work for me.
Could you explain the  
 "(!1)" part of the syntax to me?

This is what I had that did not work:

define !recode (vname=!cmdend)
!DO !cnt !IN (!vname)
temporary.
select if (!vname=1).
freq var gender.
!DOEND
execute.
!enddefine.

!recode vname=group1 group2 group3 group4.

Best,
Sven
To debug a macro, set MPRINT to ON before running it.  I.e.,

set mprint on.
!recode vname=group1 group2 group3 group4.
set mprint off.

I think in your case, you need to change !vname to !cnt in this line:

select if (!vname=1).

Also, I think you can remove the execute.
Reply | Threaded
Open this post in threaded view
|

Re: Macro question - loop!?

Florio Arguillas
S,

Regarding the !1, I used a positional parameter driven macro with a
list-processing loop.  You can find concise explanation of this in pages
567 and 577 of the SPSS Command Syntax Reference (Help>Command Syntax
Reference).

Best regards,

Florio


At 10:51 AM 2/23/2010, ksven wrote:

>Yes - both corrections are correct. I usually do use the set mprint=on, but
>it often does not tell you what
>to do - just that it's wrong!
>:-)
>S.
>
>
>
>Bruce Weaver wrote:
> >
> >
> > ksven wrote:
> >>
> >> Hi Florio -
> >> this is exactly what I was looking for. I has tried similar syntax but it
> >> did not work for me.
> >> Could you explain the
> >>  "(!1)" part of the syntax to me?
> >>
> >> This is what I had that did not work:
> >>
> >> define !recode (vname=!cmdend)
> >> !DO !cnt !IN (!vname)
> >> temporary.
> >> select if (!vname=1).
> >> freq var gender.
> >> !DOEND
> >> execute.
> >> !enddefine.
> >>
> >> !recode vname=group1 group2 group3 group4.
> >>
> >> Best,
> >> Sven
> >>
> >>
> >
> > To debug a macro, set MPRINT to ON before running it.  I.e.,
> >
> > set mprint on.
> > !recode vname=group1 group2 group3 group4.
> > set mprint off.
> >
> > I think in your case, you need to change !vname to !cnt in this line:
> >
> > select if (!vname=1).
> >
> > Also, I think you can remove the execute.
> >
> >
> >
>
>--
>View this message in context:
>http://old.nabble.com/Macro-question---loop%21--tp27695044p27705435.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
|

Help with macro for creating multiple databases

ANDRES ALBERTO BURGA LEON
In reply to this post by Bruce Weaver

Hello:

I'm trying to found a better way to do this:

I need to save in (XLS format) some variables from an SPSS *.sav, filtered by the content of  astring variable (called nom_ugel).

I mean, I need a separate file for each diferent value of nom_ugel. I've writing thins sintax for do it, but my problem is that I have 211 diferent values for nom_ugel.

Is there a way by wich I don´t need to write !ugel '030007' , !ugel '040016', etc 211 times?

Thank you very much


**************************************************************************************************.

GET FILE='D:\Censo Alumnos 2009\Definitiva\Segundo\Bases\IE CENSO 2009 2do.sav'.
DATASET NAME IE_2009 WINDOW=FRONT.

DELETE VARIABLES caracteristica3 region25 cod_eva medida_C_media_09 medida_M_media_09 n_secc_C TO p_g3_M_red_09.

DEFINE
!ruta1 ()'D:\Censo Alumnos 2009\Documentos\Reportes\UGEL\'
!ENDDEFINE.

DEFINE !ugel (!POSITIONAL !TOKENS(1))

DATASET COPY  ugel.
DATASET ACTIVATE  ugel.
FILTER OFF.
USE ALL.
SELECT IF (cod_ugel = !1).
EXECUTE.

SAVE TRANSLATE OUTFILE=!ruta1 + !QUOTE(!CONCAT(!UNQUOTE(!1) , '.xls'))
  /TYPE=XLS
  /VERSION=8
  /MAP
  /REPLACE
  /FIELDNAMES
  /CELLS=LABELS.

DATASET ACTIVATE IE_2009.
DATASET CLOSE ugel.

!ENDDEFINE.

**************************************************************************************************.
!ugel '030007'.
!ugel '040016'.
....



Mg. Andrés Burga León
Coordinador de Análisis e Informática
Unidad de Medición de la Calidad Educativa
Ministerio de Educación del Perú
Calle El Comercio s/n (espalda del Museo de la Nación)
Lima 41
Perú
Teléfono 615-5840
Reply | Threaded
Open this post in threaded view
|

Re: Help with macro for creating multiple databases

Jerabek Jindrich
Hello,

You can write the syntax hundred times very easily, it might be the fastest solution:

Just use a text editor that supports copy and paste for column blocks.
1. Copy !ugel .          as many times as you need .
2. run Frequency of the select variable.
3. Copy and paste the values to the text editor, select the column block with values and copy it to the right place (behind the name of macros).
4. Copy syntax back to the SPSS editor and it is all, syntax is ready to be used.

 HTH
Jindra



> ------------ Původní zpráva ------------
> Od: ANDRES ALBERTO BURGA LEON <[hidden email]>
> Předmět: Help with macro for creating multiple databases
> Datum: 23.2.2010 18:32:51
> ----------------------------------------
> Hello:
>
> I'm trying to found a better way to do this:
>
> I need to save in (XLS format) some variables from an SPSS *.sav, filtered
> by the content of  astring variable (called nom_ugel).
>
> I mean, I need a separate file for each diferent value of nom_ugel. I've
> writing thins sintax for do it, but my problem is that I have 211 diferent
> values for nom_ugel.
>
> Is there a way by wich I don´t need to write !ugel '030007' , !ugel
> '040016', etc 211 times?
>
> Thank you very much
>
>
> **************************************************************************************************.
>
> GET FILE='D:\Censo Alumnos 2009\Definitiva\Segundo\Bases\IE CENSO 2009
> 2do.sav'.
> DATASET NAME IE_2009 WINDOW=FRONT.
>
> DELETE VARIABLES caracteristica3 region25 cod_eva medida_C_media_09
> medida_M_media_09 n_secc_C TO p_g3_M_red_09.
>
> DEFINE
> !ruta1 ()'D:\Censo Alumnos 2009\Documentos\Reportes\UGEL\'
> !ENDDEFINE.
>
> DEFINE !ugel (!POSITIONAL !TOKENS(1))
>
> DATASET COPY  ugel.
> DATASET ACTIVATE  ugel.
> FILTER OFF.
> USE ALL.
> SELECT IF (cod_ugel = !1).
> EXECUTE.
>
> SAVE TRANSLATE OUTFILE=!ruta1 + !QUOTE(!CONCAT(!UNQUOTE(!1) , '.xls'))
>   /TYPE=XLS
>   /VERSION=8
>   /MAP
>   /REPLACE
>   /FIELDNAMES
>   /CELLS=LABELS.
>
> DATASET ACTIVATE IE_2009.
> DATASET CLOSE ugel.
>
> !ENDDEFINE.
>
> **************************************************************************************************.
> !ugel '030007'.
> !ugel '040016'.
> ....
>
>
>
> Mg. Andrés Burga León
> Coordinador de Análisis e Informática
> Unidad de Medición de la Calidad Educativa
> Ministerio de Educación del Perú
> Calle El Comercio s/n (espalda del Museo de la Nación)
> Lima 41
> Perú
> Teléfono 615-5840
>
>

=====================
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: Help with macro for creating multiple databases

Florio Arguillas
In reply to this post by ANDRES ALBERTO BURGA LEON
Hi Andres,

Aggregate your dataset using nom_ugel as your break variable.  make sure you create a new dataset containing only the aggregated variables.  Then in that new dataset, click the column header of the variable nom_ugel (this will highlight the entire column), right-click, copy, and paste the values below in between the !ugel  and the set mprint off commands.

You can even try this code using the sample values for nom_ugel below e.g. 030007 and 040016 (assuming of course these values exist in your dataset).  There is no need to quote the values because the !quote in the select if command will take care of that.

Best regards,

Florio



DEFINE !ugel (!POSITIONAL !TOKENS(2)) .

!do !nugel !in (!1).
DATASET COPY  ugel.
DATASET ACTIVATE  ugel.
FILTER OFF.
USE ALL.
SELECT IF (nom_ugel= !quote(!nugel)).
EXECUTE.

SAVE TRANSLATE OUTFILE=!QUOTE(!CONCAT('D:\Censo Alumnos 2009\Documentos\Reportes\UGEL\','nom_ugel',!nugel,'.xls'))
  /TYPE=XLS
  /VERSION=8
  /MAP
  /REPLACE
  /FIELDNAMES
  /CELLS=LABELS.

DATASET ACTIVATE dataset1.
DATASET CLOSE ugel.

!doend.

!ENDDEFINE.

set mprint on.
!ugel
030007
040016
set mprint OFF.


At 12:08 PM 2/23/2010, ANDRES ALBERTO BURGA LEON wrote:

Hello:

I'm trying to found a better way to do this:

I need to save in (XLS format) some variables from an SPSS *.sav, filtered by the content of  astring variable (called nom_ugel).

I mean, I need a separate file for each diferent value of nom_ugel. I've writing thins sintax for do it, but my problem is that I have 211 diferent values for nom_ugel.

Is there a way by wich I don´t need to write !ugel '030007' , !ugel '040016', etc 211 times?

Thank you very much


**************************************************************************************************.

GET FILE='D:\Censo Alumnos 2009\Definitiva\Segundo\Bases\IE CENSO 2009 2do.sav'.
DATASET NAME IE_2009 WINDOW=FRONT.

DELETE VARIABLES caracteristica3 region25 cod_eva medida_C_media_09 medida_M_media_09 n_secc_C TO p_g3_M_red_09.

DEFINE
!ruta1 ()'D:\Censo Alumnos 2009\Documentos\Reportes\UGEL\'
!ENDDEFINE.

DEFINE !ugel (!POSITIONAL !TOKENS(1))

DATASET COPY  ugel.
DATASET ACTIVATE  ugel.
FILTER OFF.
USE ALL.
SELECT IF (cod_ugel = !1).
EXECUTE.

SAVE TRANSLATE OUTFILE=!ruta1 + !QUOTE(!CONCAT(!UNQUOTE(!1) , '.xls'))
  /TYPE=XLS
  /VERSION=8
  /MAP
  /REPLACE
  /FIELDNAMES
  /CELLS=LABELS.

DATASET ACTIVATE IE_2009.
DATASET CLOSE ugel.

!ENDDEFINE.

**************************************************************************************************.
!ugel '030007'.
!ugel '040016'.
....



Mg. Andrés Burga León
Coordinador de Análisis e Informática
Unidad de Medición de la Calidad Educativa
Ministerio de Educación del Perú
Calle El Comercio s/n (espalda del Museo de la Nación)
Lima 41
Perú
Teléfono 615-5840


Reply | Threaded
Open this post in threaded view
|

Re: Help with macro for creating multiple databases

Florio Arguillas
In reply to this post by ANDRES ALBERTO BURGA LEON
addendum...

once you've pasted the values in between the !ugel  and the set mprint off commands, change !tokens(2)  to !tokens(211) i.e., the number of unique values of nom_ugel.



Hi Andres,

Aggregate your dataset using nom_ugel as your break variable.  make sure you create a new dataset containing only the aggregated variables.  Then in that new dataset, click the column header of the variable nom_ugel (this will highlight the entire column), right-click, copy, and paste the values below in between the !ugel  and the set mprint off commands.

You can even try this code using the sample values for nom_ugel below e.g. 030007 and 040016 (assuming of course these values exist in your dataset).  There is no need to quote the values because the !quote in the select if command will take care of that.

Best regards,

Florio



DEFINE !ugel (!POSITIONAL !TOKENS(2)) .

!do !nugel !in (!1).
DATASET COPY  ugel.
DATASET ACTIVATE  ugel.
FILTER OFF.
USE ALL.
SELECT IF (nom_ugel= !quote(!nugel)).
EXECUTE.

SAVE TRANSLATE OUTFILE=!QUOTE(!CONCAT('D:\Censo Alumnos 2009\Documentos\Reportes\UGEL\','nom_ugel',!nugel,'.xls'))
  /TYPE=XLS
  /VERSION=8
  /MAP
  /REPLACE
  /FIELDNAMES
  /CELLS=LABELS.

DATASET ACTIVATE dataset1.
DATASET CLOSE ugel.

!doend.

!ENDDEFINE.

set mprint on.
!ugel
030007
040016
set mprint OFF.


At 12:08 PM 2/23/2010, ANDRES ALBERTO BURGA LEON wrote:

Hello:

I'm trying to found a better way to do this:

I need to save in (XLS format) some variables from an SPSS *.sav, filtered by the content of  astring variable (called nom_ugel).

I mean, I need a separate file for each diferent value of nom_ugel. I've writing thins sintax for do it, but my problem is that I have 211 diferent values for nom_ugel.

Is there a way by wich I don´t need to write !ugel '030007' , !ugel '040016', etc 211 times?

Thank you very much


**************************************************************************************************.

GET FILE='D:\Censo Alumnos 2009\Definitiva\Segundo\Bases\IE CENSO 2009 2do.sav'.
DATASET NAME IE_2009 WINDOW=FRONT.

DELETE VARIABLES caracteristica3 region25 cod_eva medida_C_media_09 medida_M_media_09 n_secc_C TO p_g3_M_red_09.

DEFINE
!ruta1 ()'D:\Censo Alumnos 2009\Documentos\Reportes\UGEL\'
!ENDDEFINE.

DEFINE !ugel (!POSITIONAL !TOKENS(1))

DATASET COPY  ugel.
DATASET ACTIVATE  ugel.
FILTER OFF.
USE ALL.
SELECT IF (cod_ugel = !1).
EXECUTE.

SAVE TRANSLATE OUTFILE=!ruta1 + !QUOTE(!CONCAT(!UNQUOTE(!1) , '.xls'))
  /TYPE=XLS
  /VERSION=8
  /MAP
  /REPLACE
  /FIELDNAMES
  /CELLS=LABELS.

DATASET ACTIVATE IE_2009.
DATASET CLOSE ugel.

!ENDDEFINE.

**************************************************************************************************.
!ugel '030007'.
!ugel '040016'.
....



Mg. Andrés Burga León
Coordinador de Análisis e Informática
Unidad de Medición de la Calidad Educativa
Ministerio de Educación del Perú
Calle El Comercio s/n (espalda del Museo de la Nación)
Lima 41
Perú
Teléfono 615-5840