Running loops?

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

Running loops?

Noel-12
Hi Everyone.

I am not sure if I am making this more complicated than need be. I am working with a data set that requires the same computation to create a new variable across about 610 variables. I wrote a macro for it and then realized that none of my documentation/ manuals address not having to write out the variable names, short of running a loop. On the SPSS tools.net site I saw that you can run a macro for a series of variables without a loop but I am not seeing the application.

The set up...
Var1 ... Var610

Compute ... Where VarXFTE is the new variable.
VarXFTE = FTE * (VarX /100)

Any insight? Thank you.

Noel


Reply | Threaded
Open this post in threaded view
|

Re: Running loops?

John F Hall
do repeat
    x=var1 to var610.
    /y=newvar1 to newvar610.
compute y = x/100.
end repeat.
 
If you just want to change the values and don't need to keep the originals:
 
do repeat
    x=var1 to var610.
compute x = x/100.
end repeat.
----- Original Message -----
Sent: Wednesday, March 03, 2010 4:05 AM
Subject: Running loops?

Hi Everyone.

I am not sure if I am making this more complicated than need be. I am working with a data set that requires the same computation to create a new variable across about 610 variables. I wrote a macro for it and then realized that none of my documentation/ manuals address not having to write out the variable names, short of running a loop. On the SPSS tools.net site I saw that you can run a macro for a series of variables without a loop but I am not seeing the application.

The set up...
Var1 ... Var610

Compute ... Where VarXFTE is the new variable.
VarXFTE = FTE * (VarX /100)

Any insight? Thank you.

Noel


Reply | Threaded
Open this post in threaded view
|

Conditional Match file

ANDRES ALBERTO BURGA LEON
In reply to this post by Noel-12

Hello:

Does anybody nows how to conditionaly match variables for only some cases:

I've try:

DATASET ACTIVATE Reporte_IE.
USE ALL.
COMPUTE filtro_dre = (dre ~= '0500' AND dre ~= '0600' AND dre ~= '0900').
FILTER BY filtro_dre.
EXECUTE.
MATCH FILES /FILE=*
  /TABLE='dre'
  /BY dre nom_dre.

But this pastes que information for all cases, including those for I don't wan't the variables to be pasted. I want to keep the cases but without the information for the variables in the "dre" dataset.
One solution woulb be to paste the information for all cases, and then conditionally recode the information into SYSMISS for the cases dre ~= '0500' AND dre ~= '0600' AND dre ~= '0900'

Any sugestions on how to conditionally match variables for only certain cases?

Andres

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: Conditional Match file

Marks, Jim

Andres:

 

You can copy the cases you don’t want to match into a separate dataset, match the remaining cases then merge.

 

Not Tested.

 

DATASET ACTIVATE Reporte_IE.

DATASET copy no_match.

 

DATASET ACTIVATE no match.

SELECT IF  dre = '0500' OR dre = '0600' OR dre = '0900'.

EXECUTE.

 

DATASET ACTIVATE Reporte_IE.

SELECT IF (dre ~= '0500' AND dre ~= '0600' AND dre ~= '0900').

MATCH FILES /FILE=*
  /TABLE='dre'
  /BY dre nom_dre.

 

ADD FILES FILE = * /FILE = no_match.

EXECUTE.

 


 


 

Jim Marks

Director, Market Research

x1616

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of ANDRES ALBERTO BURGA LEON
Sent: Wednesday, March 03, 2010 4:56 PM
To: [hidden email]
Subject: Conditional Match file

 


Hello:

Does anybody nows how to conditionaly match variables for only some cases:

I've try:

DATASET ACTIVATE Reporte_IE.
USE ALL.
COMPUTE filtro_dre = (dre ~= '0500' AND dre ~= '0600' AND dre ~= '0900').
FILTER BY filtro_dre.
EXECUTE.
MATCH FILES /FILE=*
  /TABLE='dre'
  /BY dre nom_dre.

But this pastes que information for all cases, including those for I don't wan't the variables to be pasted. I want to keep the cases but without the information for the variables in the "dre" dataset.
One solution woulb be to paste the information for all cases, and then conditionally recode the information into SYSMISS for the cases dre ~= '0500' AND dre ~= '0600' AND dre ~= '0900'

Any sugestions on how to conditionally match variables for only certain cases?

Andres

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: Conditional Match file

Jarrod Teo-2
In reply to this post by ANDRES ALBERTO BURGA LEON
Hi Andres,

I am not sure if this is what you want. Please note that this syntax will create 4 files that will be on your C drive. Please do clear them away after you know what is happening.

I do hope you know macro. This is in the event that you have not decided what cases you want to leave out. This 2 macros can only leave out and keep 3 cases only though. I am just following what you had requested in your email.

In the actual work segment,

  1. I have 2 macros in which it will allow you to do selection of up to 3 string values cases only, match the file and placed it into a file directory you want. One to combine and delete the cases you do not want. One to combine and keep those cases you want.
  2. In the macro call, you will just need to fill in the required information for the codes to work.
  3. In the final output, you will have 2 files, one will contain the combined files for case 1, 12 and 13 and another file for combined files without case 1, 12 and 13.

Hope this is what you wanted.

Regards
Dorraj Oet



**********Creating the 2 files*******************.

NEW FILE.
INPUT PROGRAM.
VECTOR y(3F8.0).
LOOP v1=1 TO 100.
LOOP #cnt=1 TO 3.
COMPUTE y(#cnt)=UNIFORM(10).
END LOOP.
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
EXECUTE.

string v1n (a3).
compute v1n=string(v1,f3).

save outfile 'C:\file2.sav'
/keep v1n y1 to y3
/rename (v1n=v1).

NEW FILE.
INPUT PROGRAM.
VECTOR x(3F8.0).
LOOP v1=1 TO 100.
LOOP #cnt=1 TO 3.
COMPUTE x(#cnt)=UNIFORM(10).
END LOOP.
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
EXECUTE.

string v1n (a3).
compute v1n=string(v1,f3).

save outfile 'C:\file1.sav'
/keep v1n x1 to x3
/rename (v1n=v1).

**********Creating the 2 files*******************.

*************************Actual work*************************.

define casedelete (firstcase=!token(1)
/secondcase=! token(1)
/thirdcase=!token(1)
/savefileat=!token(1))

get file 'C:\file1.sav'.

*Selection is done on file 1 here.

select if (v1 ne !firstcase and v1 ne !secondcase and v1 ne !thirdcase).
exe.

*Matching start.

match files file=*
/table='C:\file2.sav'
by v1.
exe.

save outfile !savefileat.

!enddefine.

define casekeep (firstcase=!token(1)
/secondcase=!token(1)
/thirdcase=!token(1)
/savefileat=!token(1))

get file 'C:\file1.sav'.

*Selection is done on file 1 here.

select if (v1 eq !firstcase or v1 eq !secondcase or v1 eq !thirdcase).
exe.

*Matching start.

match files file=*
/table='C:\file2.sav'
by v1.
exe.

save outfile !savefileat.

!enddefine.

****Quote the 3 case numbers you want to delete.
****and the the place you want to save your final file at.

casedelete    firstcase='  1'    secondcase=' 12'   thirdcase= ' 13' savefileat='C:\filecombined(delete).sav'.

****Quote the 3 case numbers you want to save.
****and the the place you want to save your final file at.

casekeep    firstcase='  1'    secondcase=' 12'   thirdcase= ' 13' savefileat='C:\filecombined(keep).sav'.

get file 'C:\filecombined(delete).sav'.
get file 'C:\filecombined(keep).sav'.
*************************Actual work*************************.


Date: Wed, 3 Mar 2010 17:56:09 -0500
From: [hidden email]
Subject: Conditional Match file
To: [hidden email]


Hello:

Does anybody nows how to conditionaly match variables for only some cases:

I've try:

DATASET ACTIVATE Reporte_IE.
USE ALL.
COMPUTE filtro_dre = (dre ~= '0500' AND dre ~= '0600' AND dre ~= '0900').
FILTER BY filtro_dre.
EXECUTE.
MATCH FILES /FILE=*
  /TABLE='dre'
  /BY dre nom_dre.

But this pastes que information for all cases, including those for I don't wan't the variables to be pasted. I want to keep the cases but without the information for the variables in the "dre" dataset.
One solution woulb be to paste the information for all cases, and then conditionally recode the information into SYSMISS for the cases dre ~= '0500' AND dre ~= '0600' AND dre ~= '0900'

Any sugestions on how to conditionally match variables for only certain cases?

Andres

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


Hotmail: Trusted email with powerful SPAM protection. Sign up now.