Replace data in multiple mention (different variables)

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

Replace data in multiple mention (different variables)

Javier Figueroa

Hello SPSS experts

Again I am here to ask for your help, I have a set of variables in which I request that you enter the visited tourist site to which I assign a code to each visited site, the coding is done by department, municipality and visited site.
In a multiple mention or in different variables write down the site they do it identifying the department. for ex. Tikal, Peten and when coding this they take it as two independent sites. In the database it looks like this: place_1 = 1700000, place_2 = 1701000.
What I have to do is identify these cases and replace the department codes in this ej. it would be like this: Place_1 = sysmis, Place_2 = 1701000

Other ej. is Antigua Guatemala, Sacatepequez. at the base appears Place_1 = 301000, place_2 = 300000

Here you should remove: Place_1 = 301000, Place_2 = sysmis.


I have a syntax that I have generated and I identify them but I have not been able to replace the data.
/* procedimiento para quitar multiples.

data list list
/var1 to var10.
begin data.
1 1701000 1700000 1701001  0 0 0 0 0 0
2 301000 300000 0 0 0 0 0 0 0
3 301000 300000 0 0 0 0 0 0 0
4 1701000 1700000 0 0 0 0 0 0 0
5 3010000 1700000 0 0 0 0 0 0 0
end data.
execute.

numeric id(f8.0).
compute id=$casenum.
execute.
variable level all (scale).

/* trabajar con vectores.

VECTOR L1_1=var2 TO var10.
VECTOR y(9).

COMPUTE F1=0.
COMPUTE F2=0.
COMPUTE #y=0.

LOOP #J=1 TO 9.
-         DO IF NOT MISSING(L1_1(#J)).
-                  COMPUTE F1=0.
-                  COMPUTE F2=0.
-                  LOOP #K=1 TO 9.
-                        IF L1_1(#J)=1700000 F1=1.
-                        IF L1_1(#K)>=1701001 and L1_1(#K)<=1713001 F2=1.
-                        IF F1=1 repetido=(L1_1(#J)).
-                           compute #y=#y+1.
-                           compute y(#y)=L1_1(#K).
-                     END LOOP.
-                     DO IF F1=1 and F2=1.
-                          PRINT / 'Número Cuest.' id ' Códigos duplicados ---> ' repetido '  SET de códigos ---> '  var1 TO var10.
-                     END IF.                        
-         END IF.
END LOOP.
EXECUTE.

could you help me with this?

very grateful in advance.
--
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: Replace data in multiple mention (different variables)

David Marso
Administrator
First off you should be using a LONG data structure rather than wide one.
You painted yourself into a corner. Aye Caramba?
See VARSTOCASES.
Comment your code in English -Google Translate?- so we know WTF you are
doing at present.
Do that and repost. That is a start.





Javier Figueroa wrote

> Hello SPSS experts
>
> Again I am here to ask for your help, I have a set of variables in which I
> request that you enter the visited tourist site to which I assign a code
> to
> each visited site, the coding is done by department, municipality and
> visited site.
> In a multiple mention or in different variables write down the site they
> do
> it identifying the department. for ex. Tikal, Peten and when coding this
> they take it as two independent sites. In the database it looks like this:
> place_1 = 1700000, place_2 = 1701000.
> What I have to do is identify these cases and replace the department codes
> in this ej. it would be like this: Place_1 = sysmis, Place_2 = 1701000
>
> Other ej. is Antigua Guatemala, Sacatepequez. at the base appears Place_1
> =
> 301000, place_2 = 300000
>
> Here you should remove: Place_1 = 301000, Place_2 = sysmis.
>
>
> I have a syntax that I have generated and I identify them but I have not
> been able to replace the data.
> /* procedimiento para quitar multiples.
>
> data list list
> /var1 to var10.
> begin data.
> 1 1701000 1700000 1701001  0 0 0 0 0 0
> 2 301000 300000 0 0 0 0 0 0 0
> 3 301000 300000 0 0 0 0 0 0 0
> 4 1701000 1700000 0 0 0 0 0 0 0
> 5 3010000 1700000 0 0 0 0 0 0 0
> end data.
> execute.
>
> numeric id(f8.0).
> compute id=$casenum.
> execute.
> variable level all (scale).
>
> /* trabajar con vectores.
>
> VECTOR L1_1=var2 TO var10.
> VECTOR y(9).
>
> COMPUTE F1=0.
> COMPUTE F2=0.
> COMPUTE #y=0.
>
> LOOP #J=1 TO 9.
> -         DO IF NOT MISSING(L1_1(#J)).
> -                  COMPUTE F1=0.
> -                  COMPUTE F2=0.
> -                  LOOP #K=1 TO 9.
> -                        IF L1_1(#J)=1700000 F1=1.
> -                        IF L1_1(#K)>=1701001 and L1_1(#K)<=1713001 F2=1.
> -                        IF F1=1 repetido=(L1_1(#J)).
> -                           compute #y=#y+1.
> -                           compute y(#y)=L1_1(#K).
> -                     END LOOP.
> -                     DO IF F1=1 and F2=1.
> -                          PRINT / 'Número Cuest.' id ' Códigos duplicados
> ---> ' repetido '  SET de códigos ---> '  var1 TO var10.
> -                     END IF.
> -         END IF.
> END LOOP.
> EXECUTE.
>
> could you help me with this?
>
> very grateful in advance.
> --
>
> *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: Replace data in multiple mention (different variables)

Art Kendall
In reply to this post by Javier Figueroa
I am not sure exactly what you are trying to do.
However, it appears that you are assigning sysmis as a value.  Since the
user is assigning that value, it should be a user-missing value that is
assigned.
value of sysmis for a variable means that the SPSS software is not able to
do what you are telling it to do.

An id variable would be nominal level.

After these edits to your syntax, please repost your example syntax with
additional variables such as want01, want02, etc. to show what you want the
transformations to do.



-----
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
Reply | Threaded
Open this post in threaded view
|

Re: Replace data in multiple mention (different variables)

Javier Figueroa
Hello
Thank you very much for taking the time to read my publication and try to understand my bad English, what I need is to eliminate the mother codes from a list of possible answers. below a small explanation.

In some surveys it is usually asked what brands, products or places you remember, if you were investigating cigarettes, the question would be: What cigarette brands do you know? and the answers can be varied, some will remember the brand mother only and others will remember a category in specific of the mother brand, ex. Marlboro (mother brand) Marlboro red, hard pack. and those answers are valid, for different people but it would be invalid if one person answered Marlboro and Marlboro red, hard pack. What I try to do is eliminate the mother mark for the cases that appear as the last example and that would be Marlboro.

I am investigating tourist sites and these are divided by department, municipality and tourist site.

So for me, an error in the survey would be that they mentioned Tikal, Peten. or Antigua Guatemala, Sacatepequez, I have to eliminate the department of those who mentioned some municipality at the same time.

I already managed to locate and using a macro that rescue in the trunk of the memories eliminated the department codes that indicate that type of error.

a continuación el sintaxis que estoy utilizando. 

/* procedimiento para quitar multiples.
/* data ficticia.

data list list
/var1 to var10.
begin data.
1 1701000 1700000 1701001  0 0 0 0 0 0
2 301000 300000 0 0 0 0 0 0 0
3 301000 300000 0 0 0 0 0 0 0
4 1701000 1700000 0 0 0 0 0 0 0
5 3010000 1700000 0 0 0 0 0 0 0
end data.
execute.

numeric id(f8.0).
compute id=$casenum.
execute.
variable level all (scale).

/* trabajar con vectores.
/* Procedimiento de indentificación para eliminar marca madre. 

VECTOR L1_1=var2 TO var10.
VECTOR y(9).

COMPUTE #y=0.

LOOP #J=1 TO 9.
-         DO IF NOT MISSING(L1_1(#J)).
-                  COMPUTE F1=0.
-                  COMPUTE F2=0.
-                  LOOP #K=1 TO 9.
-                        IF L1_1(#J)=1700000 F1=1.
-                        IF L1_1(#K)>=1701000 and L1_1(#K)<=1713001 F2=1.
-                        IF L1_1(#J)=300000 F1=1.
-                        IF L1_1(#K)>=301000 and L1_1(#K)<=310001 F2=1.
-                        IF (F1=1 and F2=1) repetido=(L1_1(#J)).
-                           compute #y=#y+1.
-                           compute y(#y)=L1_1(#K).
-                     END LOOP.
-                     DO IF F1=1 and F2=1.
-                          PRINT / 'Número Cuest.' id ' Códigos duplicados ---> ' repetido '  SET de códigos ---> '  var1 TO var10.
-                     END IF.                        
-         END IF.
END LOOP.
EXECUTE.

/* MACRO PARA ELIMINACION DE CODIGOS REPETIDOS o marca madre.
define duble (!positional= !charend('|')
 /zm =!default(miss) !charend('|')) .
!let !ciag=''.
!let !jeden=''.
!let !dwa=''.
recode !1 (0=sysmis).
!do !i !in (!1).
!let !jeden=(!i).
!do !j !in (!1).
!let !dwa=(!j).
!if (!jeden<>!dwa) !then
if (!i=!j) !j=$sysmis.
!ifend.
!doend.
!doend.
!do !i !in (!1).
!let !ciag=!concat(!ciag,',',!i).
!doend.
!let !ciag=!tail(!ciag).
if (nvalid(!ciag)=0) !zm=0.
value labels /!zm 0'missing case'.
!enddefine.
*example.
duble repetido var2 var3 var4 var5 var6 var7 var8 var9 var10.
EXECUTE.

Thank you very much, for your time and suggestions.

I understand that there are many ways to program and you can find many solutions to this problem, I found this one that works for me but I know it can be simplified.

Any comments will be welcome.

Sincerely,
Best regards from Guatemala

El vie., 29 mar. 2019 a las 7:18, Art Kendall (<[hidden email]>) escribió:
I am not sure exactly what you are trying to do.
However, it appears that you are assigning sysmis as a value.  Since the
user is assigning that value, it should be a user-missing value that is
assigned.
value of sysmis for a variable means that the SPSS software is not able to
do what you are telling it to do.

An id variable would be nominal level.

After these edits to your syntax, please repost your example syntax with
additional variables such as want01, want02, etc. to show what you want the
transformations to do.



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


--
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: Replace data in multiple mention (different variables)

Maguin, Eugene

David’s very right. This is a long format data problem.

Do a varstocases and delete values of 0, so your data now look like this .

 

1 1701000

1 1700000

1 1701001 < keep

2 301000 < keep

2 300000

3 301000 < keep

3 300000

4 1701000 < keep

4 1700000

5 3010000 ?

5 1700000 ?

 

Based on how I understand what you said, the rule is to pick the largest value within var1. Is the selection for var1=1, 2, 3, 4 correct? What about var1=5, which is correct?

if 3010000 is the correct pick, use aggregate and max function. If 1700000 is correct var1=5, more information is needed.

 

Gene Maguin

 

 

 

 

 

 

From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Javier Figueroa
Sent: Friday, March 29, 2019 12:56 PM
To: [hidden email]
Subject: Re: Replace data in multiple mention (different variables)

 

Hello

Thank you very much for taking the time to read my publication and try to understand my bad English, what I need is to eliminate the mother codes from a list of possible answers. below a small explanation.

 

In some surveys it is usually asked what brands, products or places you remember, if you were investigating cigarettes, the question would be: What cigarette brands do you know? and the answers can be varied, some will remember the brand mother only and others will remember a category in specific of the mother brand, ex. Marlboro (mother brand) Marlboro red, hard pack. and those answers are valid, for different people but it would be invalid if one person answered Marlboro and Marlboro red, hard pack. What I try to do is eliminate the mother mark for the cases that appear as the last example and that would be Marlboro.

 

I am investigating tourist sites and these are divided by department, municipality and tourist site.

 

So for me, an error in the survey would be that they mentioned Tikal, Peten. or Antigua Guatemala, Sacatepequez, I have to eliminate the department of those who mentioned some municipality at the same time.

 

I already managed to locate and using a macro that rescue in the trunk of the memories eliminated the department codes that indicate that type of error.

 

a continuación el sintaxis que estoy utilizando. 

 

/* procedimiento para quitar multiples.

/* data ficticia.

 

data list list

/var1 to var10.

begin data.

1 1701000 1700000 1701001  0 0 0 0 0 0

2 301000 300000 0 0 0 0 0 0 0

3 301000 300000 0 0 0 0 0 0 0

4 1701000 1700000 0 0 0 0 0 0 0

5 3010000 1700000 0 0 0 0 0 0 0

end data.

execute.

 

numeric id(f8.0).

compute id=$casenum.

execute.

variable level all (scale).

 

/* trabajar con vectores.

/* Procedimiento de indentificación para eliminar marca madre. 

 

VECTOR L1_1=var2 TO var10.

VECTOR y(9).

 

COMPUTE #y=0.

 

LOOP #J=1 TO 9.

-         DO IF NOT MISSING(L1_1(#J)).

-                  COMPUTE F1=0.

-                  COMPUTE F2=0.

-                  LOOP #K=1 TO 9.

-                        IF L1_1(#J)=1700000 F1=1.

-                        IF L1_1(#K)>=1701000 and L1_1(#K)<=1713001 F2=1.

-                        IF L1_1(#J)=300000 F1=1.

-                        IF L1_1(#K)>=301000 and L1_1(#K)<=310001 F2=1.

-                                  IF (F1=1 and F2=1) repetido=(L1_1(#J)).

-                           compute #y=#y+1.

-                           compute y(#y)=L1_1(#K).

-                     END LOOP.

-                     DO IF F1=1 and F2=1.

-                                                PRINT / 'Número Cuest.' id ' Códigos duplicados ---> ' repetido '  SET de códigos ---> '  var1 TO var10.

-                     END IF.                        

-         END IF.

END LOOP.

EXECUTE.

 

/* MACRO PARA ELIMINACION DE CODIGOS REPETIDOS o marca madre.

define duble (!positional= !charend('|')

 /zm =!default(miss) !charend('|')) .

!let !ciag=''.

!let !jeden=''.

!let !dwa=''.

recode !1 (0=sysmis).

!do !i !in (!1).

!let !jeden=(!i).

!do !j !in (!1).

!let !dwa=(!j).

!if (!jeden<>!dwa) !then

if (!i=!j) !j=$sysmis.

!ifend.

!doend.

!doend.

!do !i !in (!1).

!let !ciag=!concat(!ciag,',',!i).

!doend.

!let !ciag=!tail(!ciag).

if (nvalid(!ciag)=0) !zm=0.

value labels /!zm 0'missing case'.

!enddefine.

*example.

duble repetido var2 var3 var4 var5 var6 var7 var8 var9 var10.

EXECUTE.

 

Thank you very much, for your time and suggestions.

 

I understand that there are many ways to program and you can find many solutions to this problem, I found this one that works for me but I know it can be simplified.

 

Any comments will be welcome.

 

Sincerely,

Best regards from Guatemala

 

El vie., 29 mar. 2019 a las 7:18, Art Kendall (<[hidden email]>) escribió:

I am not sure exactly what you are trying to do.
However, it appears that you are assigning sysmis as a value.  Since the
user is assigning that value, it should be a user-missing value that is
assigned.
value of sysmis for a variable means that the SPSS software is not able to
do what you are telling it to do.

An id variable would be nominal level.

After these edits to your syntax, please repost your example syntax with
additional variables such as want01, want02, etc. to show what you want the
transformations to do.



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


 

--

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

===================== 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: Replace data in multiple mention (different variables)

Art Kendall
In reply to this post by Javier Figueroa
Is it correct to assume that a department is a wider geographic/political
unit and sites are more specific geographically withing a department?

Do the 4 least significant digits (rightmost characters) always designate a
site, and the 2 or 3 most significant digits designate the department?






-----
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
Reply | Threaded
Open this post in threaded view
|

Re: Replace data in multiple mention (different variables)

Javier Figueroa
Hello, Art Kendall

Yes, the tourist sites are within the departments, I could know what department is only for the tourist site. The codebook is prepared specifically for that purpose:

The first two digits are from 1 to 22 that are the departments the following two digits are from municipality that can be from 1 to 99 (the department that has more municipalities is Huehuetenango that have 33 municipalities) and the last 3 digits are the tourist site

17 = Peten
01 = Flores
002 = Petencito / Zoologíco
(1701002)

1700000 Petén
1700001 Tikal/ el gran jaguar
1700002 Río Mopán
1700003 Yaxhá
1700004 El Remate
1700005 Lago Petén Itzá
1700006 Ixpanpajul
1700007 Uaxactún
1700008 San miguel peten
1700009 Centros comerciales/ mayan mall/ petro plaza
1701000 Flores
1701001  
1701002 Petencito/zoologico
1701003 Isla de Flores
1701004 Playa Chechenal
1701005 ruinas de Auxactún

03 = Sacatepéquez
01 = Antigua Guatemala
001 = Palacio de los Capitanes Generales
(301001)

300000 Sacatepéquez
301000 Antigua Guatemala
301001 Palacio de los Capitanes Generales
301002 Hobbitenango
301003 Los Encuentros
301004 Cerro de la Cruz/ mirador
301005 Arco de Santa Catalina

then syntax to be used in the database with 500,000 records.

/* procedimiento para quitar multiples.
/* data ficticia.

data list list
/Lugar1_1_Cod to Lugar1_12_Cod.
begin data.
1 1701000 1700000 1701001  0 0 0 0 0 0 0 0
2 301000 300000 0 0 0 0 0 0 0 0 0
3 301000 300000 0 0 0 0 0 0 0 0 0
4 1701000 1700000 0 0 0 0 0 0 0 0 0
5 3010000 1700000 0 0 0 0 0 0 0 0 0
end data.
execute.

numeric id(f8.0).
compute id=$casenum.
execute.
variable level all (scale).

/* trabajar con vectores.
/* Procedimiento de indentificación para eliminar marca madre. 

VECTOR L1_1=Lugar1_1_Cod TO Lugar1_12_Cod.
VECTOR y(12).

COMPUTE #y=0.

LOOP #J=1 TO 12.
-         DO IF NOT MISSING(L1_1(#J)).
-                  COMPUTE F1=0.
-                  COMPUTE F2=0.
-                  LOOP #K=1 TO 12.
-                        IF L1_1(#J)=101000 F1=1.   /* GUATEMALA.
-                        IF L1_1(#K)>=101001 and L1_1(#K)<=118000 F2=1.   /* MUNICIPIOS GUATEMALA
-                        IF L1_1(#J)=200000 F1=1.  /* EL PROGRESO.
-                        IF L1_1(#K)>=201000 and L1_1(#K)<=208000 F2=1.   /* MUNICIPIOS EL PROGRESO.
-                        IF L1_1(#J)=300000 F1=1.  /* SACATEPÉQUEZ.
-                        IF L1_1(#K)>=301000 and L1_1(#K)<=315101 F2=1.   /* MUNICIÍOS SACATEPÉQUEZ.
-                        IF L1_1(#J)=400000 F1=1.  /*CHIMALTENANGO.
-                        IF L1_1(#K)>=400001 and L1_1(#K)<=415000 F2=1.   /* MUNICIPÍOS CHIMALTENANGO.
-                        IF L1_1(#J)=500000 F1=1.  /*ESCUINTLA.
-                        IF L1_1(#K)>=500001 and L1_1(#K)<=580000 F2=1.   /* MUNICIPÍOS ESCUINTLA.
-                        IF L1_1(#J)=600000 F1=1.  /*SANTA ROSA.
-                        IF L1_1(#K)>=600001 and L1_1(#K)<=614000 F2=1.   /* MUNICIPÍOS SANTA ROSA.
-                        IF L1_1(#J)=700000 F1=1.  /*SOLOLÁ.
-                        IF L1_1(#K)>=700001 and L1_1(#K)<=719001 F2=1.   /* MUNICIPÍOS SANTA ROSA.
-                        IF L1_1(#J)=800000 F1=1.  /*TOTONICAPÁN.
-                        IF L1_1(#K)>=801000 and L1_1(#K)<=807000 F2=1.   /* MUNICIPÍOS TOTONICAPAN.
-                        IF L1_1(#J)=900000 F1=1.  /*QUETZALTENANGO.
-                        IF L1_1(#K)>=900001 and L1_1(#K)<=940000 F2=1.   /* MUNICIPÍOS QUETZALTENANGO.
-                        IF L1_1(#J)=1000000 F1=1.  /*SUCHITEPEQUEZ.
-                        IF L1_1(#K)>=1001001 and L1_1(#K)<=1021000 F2=1.  /* MUNICIPOÍOS SUCHITEPEQUEZ.
-                        IF L1_1(#J)=1100000 F1=1.  /*RETALHULEU.
-                        IF L1_1(#K)>=1100001 and L1_1(#K)<=1108001 F2=1.  /* MUNICIPIOS RETALHULEU.
-                        IF L1_1(#J)=1200000 F1=1.  /*SAN MARCOS.
-                        IF L1_1(#K)>=1200001 and L1_1(#K)<=1290001 F2=1.  /* MUNICIPÍOS SAN MARCOS.
-                        IF L1_1(#J)=1301000 F1=1.  /*HUEHUETENANGO.
-                        IF L1_1(#K)>=1301001 and L1_1(#K)<=1331000 F2=1.  /* MUNICIPÍOS HUEHUETENANGO.
-                        IF L1_1(#J)=1401000 F1=1.  /*QUICHÉ.
-                        IF L1_1(#K)>=1402000 and L1_1(#K)<=1419000 F2=1.  /*MUNICIPIOS QUICHÉ.
-                        IF L1_1(#J)=1501000 F1=1.  /*BAJA VERAPAZ.
-                        IF L1_1(#K)>=1502000 and L1_1(#K)<=1508001 F2=1.  /* MUNICIPIOS BAJA VERAPAZ.
-                        IF L1_1(#J)=1600000 F1=1.   /*ALTA VERAPAZ.
-                        IF L1_1(#K)>=1600001 and L1_1(#K)<=1617000 F2=1.  /*MUNICIPIOS ALTA VERAPAZ.
-                        IF L1_1(#J)=1700000 F1=1.   /*PETÉN.
-                        IF L1_1(#K)>=1700001 and L1_1(#K)<=1713001 F2=1.   /*MUNICIPÍOS PETÉN.
-                        IF L1_1(#J)=1800000 F1=1.   /*IZABAL.
-                        IF L1_1(#K)>=1800001 and L1_1(#K)<=1805005 F2=1.   /*MUNICIPÍOS IZABAL.
-                        IF L1_1(#J)=1900000 F1=1.  /*ZACAPA.
-                        IF L1_1(#K)>=1900001 and L1_1(#K)<=1910000 F2=1.   /* MUNICIPÍOS ZACAPA.
-                        IF L1_1(#J)=2000000 F1=1.  /*CHIQUIMULA.
-                        IF L1_1(#K)>=2000001 and L1_1(#K)<=2010000 F2=1.   /* MUNICIPÍOS CHIQUIMULA.
-                        IF L1_1(#J)=2100000 F1=1.   /*JALAPA.
-                        IF L1_1(#K)>=2100001 and L1_1(#K)<=2106003 F2=1.   /*MUNICIPÍOS JALAPA.
-                        IF L1_1(#J)=2200000 F1=1.   /*JUTIAPA.
-                        IF L1_1(#K)>=2200001 and L1_1(#K)<=2215000 F2=1.   /* MUNICIPÍOS JUTIAPA.
-                        IF (F1=1 and F2=1) repetido=(L1_1(#J)).
-                           compute #y=#y+1.
-                           compute y(#y)=L1_1(#K).  /*COPIA DE DATOS ORIGINALES.
-                     END LOOP.
-                     DO IF F1=1 and F2=1.
-                          PRINT / 'Número Cuest.' Correlativo1 ' Códigos duplicados ---> ' repetido '  SET de códigos ---> '  Lugar1_1_Cod TO Lugar1_12_Cod. /*LISTA DE ERRORES.
-                     END IF.                        
-         END IF.
END LOOP.
EXECUTE.

/* MACRO PARA ELIMINACION DE CODIGOS REPETIDOS o marca madre.
define duble (!positional= !charend('|')
 /zm =!default(miss) !charend('|')) .
!let !ciag=''.
!let !jeden=''.
!let !dwa=''.
recode !1 (0=sysmis).
!do !i !in (!1).
!let !jeden=(!i).
!do !j !in (!1).
!let !dwa=(!j).
!if (!jeden<>!dwa) !then
if (!i=!j) !j=$sysmis.
!ifend.
!doend.
!doend.
!do !i !in (!1).
!let !ciag=!concat(!ciag,',',!i).
!doend.
!let !ciag=!tail(!ciag).
if (nvalid(!ciag)=0) !zm=0.
value labels /!zm 0'missing case'.
!enddefine.
*example remplazo en variables originales.
duble repetido Lugar1_1_Cod Lugar1_2_Cod Lugar1_3_Cod Lugar1_4_Cod Lugar1_5_Cod Lugar1_6_Cod Lugar1_7_Cod Lugar1_8_Cod Lugar1_9_Cod Lugar1_10_Cod Lugar1_11_Cod Lugar1_12_Cod.
EXECUTE.


I know that this process can be generated in many ways, if you would like to contribute or facilitate the process the suggestions will be welcome.

Many thanks again to this community of SPSS experts for their time.

regards


El vie., 29 mar. 2019 a las 14:21, Art Kendall (<[hidden email]>) escribió:
Is it correct to assume that a department is a wider geographic/political
unit and sites are more specific geographically withing a department?

Do the 4 least significant digits (rightmost characters) always designate a
site, and the 2 or 3 most significant digits designate the department?






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


--
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: Replace data in multiple mention (different variables)

PRogman
Please use descriptive variable names!
What is var1? var2-var10? F1, F2, y....
Assume data list value 0 is missing data?
Are really all variables SCALE?? looks more like NOMINAL, according to your
code book, and should be of type (N7) ...or maybe even a string...
You do need long data format.

Your entries are position-coded department(1-2), Municipality(3-4) and
TouristSite(5-7).

In your demo data all var2 have municipality, and all var3 are missing
municipality, and all Sites are 000?
I assume you are combining municipalities to larger (department) unit:  
   IF L1_1(#K)>=101001 and L1_1(#K)<=118000 F2=1.   /* MUNICIPIOS GUATEMALA
Do you always have at least 2 entries (var2 and var3)?

You want to 'eliminate the mother codes from a list of possible answers'.
What does that mean exactly? Removing Department and/or Municipality??

Parse the site code to its components to get your selection.
This is my interpretation of your code, without understanding what you
exactly want.

HTH, PR

**********************************************.
data list list
/var1 to var10.
begin data.
1 1701000 1700000 1701001  0 0 0 0 0 0
2  301000  300000       0  0 0 0 0 0 0
3  301000  300000       0  0 0 0 0 0 0
4 1701000 1700000       0  0 0 0 0 0 0
5 3010000 1700000       0  0 0 0 0 0 0
end data.
execute.

numeric id(f8.0).
compute id=$casenum.
execute.
variable level all (scale).

FORMATS  var1 (F8.0).
* To long format *.
VARSTOCASES
  /MAKE    TouristSite FROM var2 var3 var4 var5 var6 var7 var8 var9 var10
  /INDEX = VisitID(9)
  /KEEP  = var1
.
* Remove missing site data values (0) *.
SELECT IF (TouristSite NE 0).

* Parse Site code. Municipality includes Department *.
COMPUTE Department   = TRUNC(TouristSite/100000).
COMPUTE Municipality = TRUNC(TouristSite/1000).
* maybe LocalSite is useful? *.
COMPUTE LocalSite    = MOD(TouristSite, 1000).
FORMATS
  Department   (N2)
  Municipality (N4)
  LocalSite    (N3)
.
VARIABLE LEVEL  Department Municipality LocalSite (NOMINAL).
EXECUTE.

* Identify Duplicate Cases = var1+Department *.
  /FILE  = *
  /BY      var1 Department
  /FIRST = PrimaryFirst
  /LAST  = PrimaryLast.
DO IF (PrimaryFirst).
  COMPUTE MatchSequence = 1 - PrimaryLast.
ELSE.
  COMPUTE MatchSequence = MatchSequence + 1.
END IF.
LEAVE     MatchSequence.
FORMATS   MatchSequence (F7).
MATCH FILES
  /FILE = *
  /DROP = PrimaryFirst PrimaryLast.
VARIABLE LABELS MatchSequence 'Sequential count of matching cases'.
VARIABLE LEVEL  MatchSequence (SCALE).
EXECUTE.

* Remove duplicate Department within var1 *.
SELECT IF (MatchSequence LE 1).
EXECUTE.
DELETE VARIABLES MatchSequence.

LIST ALL.

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

 
Javier Figueroa wrote

> Hello, Art Kendall
>
> Yes, the tourist sites are within the departments, I could know what
> department is only for the tourist site. The codebook is prepared
> specifically for that purpose:
>
> The first two digits are from 1 to 22 that are the departments the
> following two digits are from municipality that can be from 1 to 99 (the
> department that has more municipalities is Huehuetenango that have 33
> municipalities) and the last 3 digits are the tourist site
>
> 17 = Peten
> 01 = Flores
> 002 = Petencito / Zoologíco
> (1701002)
>
> 1700000 Petén
> 1700001 Tikal/ el gran jaguar
> 1700002 Río Mopán
> 1700003 Yaxhá
> 1700004 El Remate
> 1700005 Lago Petén Itzá
> 1700006 Ixpanpajul
> 1700007 Uaxactún
> 1700008 San miguel peten
> 1700009 Centros comerciales/ mayan mall/ petro plaza
> 1701000 Flores
> 1701001
> 1701002 Petencito/zoologico
> 1701003 Isla de Flores
> 1701004 Playa Chechenal
> 1701005 ruinas de Auxactún
>
> 03 = Sacatepéquez
> 01 = Antigua Guatemala
> 001 = Palacio de los Capitanes Generales
> (301001)
>
> 300000 Sacatepéquez
> 301000 Antigua Guatemala
> 301001 Palacio de los Capitanes Generales
> 301002 Hobbitenango
> 301003 Los Encuentros
> 301004 Cerro de la Cruz/ mirador
> 301005 Arco de Santa Catalina
>
> then syntax to be used in the database with 500,000 records.
>
> /* procedimiento para quitar multiples.
> /* data ficticia.
>
> data list list
> /Lugar1_1_Cod to Lugar1_12_Cod.
> begin data.
> 1 1701000 1700000 1701001  0 0 0 0 0 0 0 0
> 2 301000 300000 0 0 0 0 0 0 0 0 0
> 3 301000 300000 0 0 0 0 0 0 0 0 0
> 4 1701000 1700000 0 0 0 0 0 0 0 0 0
> 5 3010000 1700000 0 0 0 0 0 0 0 0 0
> end data.
> execute.
>
> numeric id(f8.0).
> compute id=$casenum.
> execute.
> variable level all (scale).
>
> /* trabajar con vectores.
> /* Procedimiento de indentificación para eliminar marca madre.
>
> VECTOR L1_1=Lugar1_1_Cod TO Lugar1_12_Cod.
> VECTOR y(12).
>
> COMPUTE #y=0.
>
> LOOP #J=1 TO 12.
> -         DO IF NOT MISSING(L1_1(#J)).
> -                  COMPUTE F1=0.
> -                  COMPUTE F2=0.
> -                  LOOP #K=1 TO 12.
> -                        IF L1_1(#J)=101000 F1=1.   /* GUATEMALA.
> -                        IF L1_1(#K)>=101001 and L1_1(#K)<=118000 F2=1.
>  /* MUNICIPIOS GUATEMALA
> -                        IF L1_1(#J)=200000 F1=1.  /* EL PROGRESO.
> -                        IF L1_1(#K)>=201000 and L1_1(#K)<=208000 F2=1.
>  /* MUNICIPIOS EL PROGRESO.
> -                        IF L1_1(#J)=300000 F1=1.  /* SACATEPÉQUEZ.
> -                        IF L1_1(#K)>=301000 and L1_1(#K)<=315101 F2=1.
>  /* MUNICIÍOS SACATEPÉQUEZ.
> -                        IF L1_1(#J)=400000 F1=1.  /*CHIMALTENANGO.
> -                        IF L1_1(#K)>=400001 and L1_1(#K)<=415000 F2=1.
>  /* MUNICIPÍOS CHIMALTENANGO.
> -                        IF L1_1(#J)=500000 F1=1.  /*ESCUINTLA.
> -                        IF L1_1(#K)>=500001 and L1_1(#K)<=580000 F2=1.
>  /* MUNICIPÍOS ESCUINTLA.
> -                        IF L1_1(#J)=600000 F1=1.  /*SANTA ROSA.
> -                        IF L1_1(#K)>=600001 and L1_1(#K)<=614000 F2=1.
>  /* MUNICIPÍOS SANTA ROSA.
> -                        IF L1_1(#J)=700000 F1=1.  /*SOLOLÁ.
> -                        IF L1_1(#K)>=700001 and L1_1(#K)<=719001 F2=1.
>  /* MUNICIPÍOS SANTA ROSA.
> -                        IF L1_1(#J)=800000 F1=1.  /*TOTONICAPÁN.
> -                        IF L1_1(#K)>=801000 and L1_1(#K)<=807000 F2=1.
>  /* MUNICIPÍOS TOTONICAPAN.
> -                        IF L1_1(#J)=900000 F1=1.  /*QUETZALTENANGO.
> -                        IF L1_1(#K)>=900001 and L1_1(#K)<=940000 F2=1.
>  /* MUNICIPÍOS QUETZALTENANGO.
> -                        IF L1_1(#J)=1000000 F1=1.  /*SUCHITEPEQUEZ.
> -                        IF L1_1(#K)>=1001001 and L1_1(#K)<=1021000 F2=1.
> /* MUNICIPOÍOS SUCHITEPEQUEZ.
> -                        IF L1_1(#J)=1100000 F1=1.  /*RETALHULEU.
> -                        IF L1_1(#K)>=1100001 and L1_1(#K)<=1108001 F2=1.
> /* MUNICIPIOS RETALHULEU.
> -                        IF L1_1(#J)=1200000 F1=1.  /*SAN MARCOS.
> -                        IF L1_1(#K)>=1200001 and L1_1(#K)<=1290001 F2=1.
> /* MUNICIPÍOS SAN MARCOS.
> -                        IF L1_1(#J)=1301000 F1=1.  /*HUEHUETENANGO.
> -                        IF L1_1(#K)>=1301001 and L1_1(#K)<=1331000 F2=1.
> /* MUNICIPÍOS HUEHUETENANGO.
> -                        IF L1_1(#J)=1401000 F1=1.  /*QUICHÉ.
> -                        IF L1_1(#K)>=1402000 and L1_1(#K)<=1419000 F2=1.
> /*MUNICIPIOS QUICHÉ.
> -                        IF L1_1(#J)=1501000 F1=1.  /*BAJA VERAPAZ.
> -                        IF L1_1(#K)>=1502000 and L1_1(#K)<=1508001 F2=1.
> /* MUNICIPIOS BAJA VERAPAZ.
> -                        IF L1_1(#J)=1600000 F1=1.   /*ALTA VERAPAZ.
> -                        IF L1_1(#K)>=1600001 and L1_1(#K)<=1617000 F2=1.
> /*MUNICIPIOS ALTA VERAPAZ.
> -                        IF L1_1(#J)=1700000 F1=1.   /*PETÉN.
> -                        IF L1_1(#K)>=1700001 and L1_1(#K)<=1713001 F2=1.
>  /*MUNICIPÍOS PETÉN.
> -                        IF L1_1(#J)=1800000 F1=1.   /*IZABAL.
> -                        IF L1_1(#K)>=1800001 and L1_1(#K)<=1805005 F2=1.
>  /*MUNICIPÍOS IZABAL.
> -                        IF L1_1(#J)=1900000 F1=1.  /*ZACAPA.
> -                        IF L1_1(#K)>=1900001 and L1_1(#K)<=1910000 F2=1.
>  /* MUNICIPÍOS ZACAPA.
> -                        IF L1_1(#J)=2000000 F1=1.  /*CHIQUIMULA.
> -                        IF L1_1(#K)>=2000001 and L1_1(#K)<=2010000 F2=1.
>  /* MUNICIPÍOS CHIQUIMULA.
> -                        IF L1_1(#J)=2100000 F1=1.   /*JALAPA.
> -                        IF L1_1(#K)>=2100001 and L1_1(#K)<=2106003 F2=1.
>  /*MUNICIPÍOS JALAPA.
> -                        IF L1_1(#J)=2200000 F1=1.   /*JUTIAPA.
> -                        IF L1_1(#K)>=2200001 and L1_1(#K)<=2215000 F2=1.
>  /* MUNICIPÍOS JUTIAPA.
> -                        IF (F1=1 and F2=1) repetido=(L1_1(#J)).
> -                           compute #y=#y+1.
> -                           compute y(#y)=L1_1(#K).  /*COPIA DE DATOS
> ORIGINALES.
> -                     END LOOP.
> -                     DO IF F1=1 and F2=1.
> -                          PRINT / 'Número Cuest.' Correlativo1 ' Códigos
> duplicados ---> ' repetido '  SET de códigos ---> '  Lugar1_1_Cod TO
> Lugar1_12_Cod. /*LISTA DE ERRORES.
> -                     END IF.
> -         END IF.
> END LOOP.
> EXECUTE.
>
> /* MACRO PARA ELIMINACION DE CODIGOS REPETIDOS o marca madre.
> define duble (!positional= !charend('|')
>  /zm =!default(miss) !charend('|')) .
> !let !ciag=''.
> !let !jeden=''.
> !let !dwa=''.
> recode !1 (0=sysmis).
> !do !i !in (!1).
> !let !jeden=(!i).
> !do !j !in (!1).
> !let !dwa=(!j).
> !if (!jeden<>!dwa) !then
> if (!i=!j) !j=$sysmis.
> !ifend.
> !doend.
> !doend.
> !do !i !in (!1).
> !let !ciag=!concat(!ciag,',',!i).
> !doend.
> !let !ciag=!tail(!ciag).
> if (nvalid(!ciag)=0) !zm=0.
> value labels /!zm 0'missing case'.
> !enddefine.
> *example remplazo en variables originales.
> duble repetido Lugar1_1_Cod Lugar1_2_Cod Lugar1_3_Cod Lugar1_4_Cod
> Lugar1_5_Cod Lugar1_6_Cod Lugar1_7_Cod Lugar1_8_Cod Lugar1_9_Cod
> Lugar1_10_Cod Lugar1_11_Cod Lugar1_12_Cod.
> EXECUTE.
>
>
> I know that this process can be generated in many ways, if you would like
> to contribute or facilitate the process the suggestions will be welcome.
>
> Many thanks again to this community of SPSS experts for their time.
>
> regards
>
>
> El vie., 29 mar. 2019 a las 14:21, Art Kendall (&lt;

> Art@

> &gt;)
> escribió:
>
>> Is it correct to assume that a department is a wider geographic/political
>> unit and sites are more specific geographically withing a department?
>>
>> Do the 4 least significant digits (rightmost characters) always designate
>> a
>> site, and the 2 or 3 most significant digits designate the department?
>>
>>
>>
>>
>>
>>
>> -----
>> 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
>>

> 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





--
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
Reply | Threaded
Open this post in threaded view
|

Re: Replace data in multiple mention (different variables)

Javier Figueroa

Hello!!!!! 


PRogman






 


I assume you are combining municipalities to larger (department) unit:  
   IF L1_1(#K)>=101001 and L1_1(#K)<=118000 F2=1.   /* MUNICIPIOS GUATEMALA
Do you always have at least 2 entries (var2 and var3)?   

              - Yes, I showed them that way because they are the most common cases, peten and sacatepequez, cod. 17 and 03 respectively in the                   variables var2 Department.

             - Yes, it is a multiple choice response, a visitor could visit several munitions and / or tourist sites.

You want to 'eliminate the mother codes from a list of possible answers'.
What does that mean exactly? Removing Department and/or Municipality??


            - I need to delete the code of the department and / or municipality when it is mentioned as a complement to the tourist site because the                 department and / or municipality can be determined only with the tourist site.

             Ex no. one
             Question: What places have you visited on this trip?
             Answer: Tikal, Peten
            Coding: 1701001, 1700000
           Ex no. two
           Question: What places have you visited on this trip?
          Answer: Antigua Guatemala, Sacatepequez
          Coding: 0301000, 0300000

I can not do it transposing the data because I need to keep the base as it is typed, since I have a history and I can not do it with identifying duplicate data because they are different codes

Thank you very much for your answers.

Sincerely,


El sáb., 30 mar. 2019 a las 12:28, PRogman (<[hidden email]>) escribió:
Please use descriptive variable names!
What is var1? var2-var10? F1, F2, y....
Assume data list value 0 is missing data?
Are really all variables SCALE?? looks more like NOMINAL, according to your
code book, and should be of type (N7) ...or maybe even a string...
You do need long data format.

Your entries are position-coded department(1-2), Municipality(3-4) and
TouristSite(5-7).

In your demo data all var2 have municipality, and all var3 are missing
municipality, and all Sites are 000?
I assume you are combining municipalities to larger (department) unit: 
   IF L1_1(#K)>=101001 and L1_1(#K)<=118000 F2=1.   /* MUNICIPIOS GUATEMALA
Do you always have at least 2 entries (var2 and var3)?

You want to 'eliminate the mother codes from a list of possible answers'.
What does that mean exactly? Removing Department and/or Municipality??

Parse the site code to its components to get your selection.
This is my interpretation of your code, without understanding what you
exactly want.

HTH, PR

**********************************************.
data list list
/var1 to var10.
begin data.
1 1701000 1700000 1701001  0 0 0 0 0 0
2  301000  300000       0  0 0 0 0 0 0
3  301000  300000       0  0 0 0 0 0 0
4 1701000 1700000       0  0 0 0 0 0 0
5 3010000 1700000       0  0 0 0 0 0 0
end data.
execute.

numeric id(f8.0).
compute id=$casenum.
execute.
variable level all (scale).

FORMATS  var1 (F8.0).
* To long format *.
VARSTOCASES
  /MAKE    TouristSite FROM var2 var3 var4 var5 var6 var7 var8 var9 var10
  /INDEX = VisitID(9)
  /KEEP  = var1
.
* Remove missing site data values (0) *.
SELECT IF (TouristSite NE 0).

* Parse Site code. Municipality includes Department *.
COMPUTE Department   = TRUNC(TouristSite/100000).
COMPUTE Municipality = TRUNC(TouristSite/1000).
* maybe LocalSite is useful? *.
COMPUTE LocalSite    = MOD(TouristSite, 1000).
FORMATS
  Department   (N2)
  Municipality (N4)
  LocalSite    (N3)
.
VARIABLE LEVEL  Department Municipality LocalSite (NOMINAL).
EXECUTE.

* Identify Duplicate Cases = var1+Department *.
  /FILE  = *
  /BY      var1 Department
  /FIRST = PrimaryFirst
  /LAST  = PrimaryLast.
DO IF (PrimaryFirst).
  COMPUTE MatchSequence = 1 - PrimaryLast.
ELSE.
  COMPUTE MatchSequence = MatchSequence + 1.
END IF.
LEAVE     MatchSequence.
FORMATS   MatchSequence (F7).
MATCH FILES
  /FILE = *
  /DROP = PrimaryFirst PrimaryLast.
VARIABLE LABELS MatchSequence 'Sequential count of matching cases'.
VARIABLE LEVEL  MatchSequence (SCALE).
EXECUTE.

* Remove duplicate Department within var1 *.
SELECT IF (MatchSequence LE 1).
EXECUTE.
DELETE VARIABLES MatchSequence.

LIST ALL.

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


Javier Figueroa wrote
> Hello, Art Kendall
>
> Yes, the tourist sites are within the departments, I could know what
> department is only for the tourist site. The codebook is prepared
> specifically for that purpose:
>
> The first two digits are from 1 to 22 that are the departments the
> following two digits are from municipality that can be from 1 to 99 (the
> department that has more municipalities is Huehuetenango that have 33
> municipalities) and the last 3 digits are the tourist site
>
> 17 = Peten
> 01 = Flores
> 002 = Petencito / Zoologíco
> (1701002)
>
> 1700000 Petén
> 1700001 Tikal/ el gran jaguar
> 1700002 Río Mopán
> 1700003 Yaxhá
> 1700004 El Remate
> 1700005 Lago Petén Itzá
> 1700006 Ixpanpajul
> 1700007 Uaxactún
> 1700008 San miguel peten
> 1700009 Centros comerciales/ mayan mall/ petro plaza
> 1701000 Flores
> 1701001
> 1701002 Petencito/zoologico
> 1701003 Isla de Flores
> 1701004 Playa Chechenal
> 1701005 ruinas de Auxactún
>
> 03 = Sacatepéquez
> 01 = Antigua Guatemala
> 001 = Palacio de los Capitanes Generales
> (301001)
>
> 300000 Sacatepéquez
> 301000 Antigua Guatemala
> 301001 Palacio de los Capitanes Generales
> 301002 Hobbitenango
> 301003 Los Encuentros
> 301004 Cerro de la Cruz/ mirador
> 301005 Arco de Santa Catalina
>
> then syntax to be used in the database with 500,000 records.
>
> /* procedimiento para quitar multiples.
> /* data ficticia.
>
> data list list
> /Lugar1_1_Cod to Lugar1_12_Cod.
> begin data.
> 1 1701000 1700000 1701001  0 0 0 0 0 0 0 0
> 2 301000 300000 0 0 0 0 0 0 0 0 0
> 3 301000 300000 0 0 0 0 0 0 0 0 0
> 4 1701000 1700000 0 0 0 0 0 0 0 0 0
> 5 3010000 1700000 0 0 0 0 0 0 0 0 0
> end data.
> execute.
>
> numeric id(f8.0).
> compute id=$casenum.
> execute.
> variable level all (scale).
>
> /* trabajar con vectores.
> /* Procedimiento de indentificación para eliminar marca madre.
>
> VECTOR L1_1=Lugar1_1_Cod TO Lugar1_12_Cod.
> VECTOR y(12).
>
> COMPUTE #y=0.
>
> LOOP #J=1 TO 12.
> -         DO IF NOT MISSING(L1_1(#J)).
> -                  COMPUTE F1=0.
> -                  COMPUTE F2=0.
> -                  LOOP #K=1 TO 12.
> -                        IF L1_1(#J)=101000 F1=1.   /* GUATEMALA.
> -                        IF L1_1(#K)>=101001 and L1_1(#K)<=118000 F2=1.
>  /* MUNICIPIOS GUATEMALA
> -                        IF L1_1(#J)=200000 F1=1.  /* EL PROGRESO.
> -                        IF L1_1(#K)>=201000 and L1_1(#K)<=208000 F2=1.
>  /* MUNICIPIOS EL PROGRESO.
> -                        IF L1_1(#J)=300000 F1=1.  /* SACATEPÉQUEZ.
> -                        IF L1_1(#K)>=301000 and L1_1(#K)<=315101 F2=1.
>  /* MUNICIÍOS SACATEPÉQUEZ.
> -                        IF L1_1(#J)=400000 F1=1.  /*CHIMALTENANGO.
> -                        IF L1_1(#K)>=400001 and L1_1(#K)<=415000 F2=1.
>  /* MUNICIPÍOS CHIMALTENANGO.
> -                        IF L1_1(#J)=500000 F1=1.  /*ESCUINTLA.
> -                        IF L1_1(#K)>=500001 and L1_1(#K)<=580000 F2=1.
>  /* MUNICIPÍOS ESCUINTLA.
> -                        IF L1_1(#J)=600000 F1=1.  /*SANTA ROSA.
> -                        IF L1_1(#K)>=600001 and L1_1(#K)<=614000 F2=1.
>  /* MUNICIPÍOS SANTA ROSA.
> -                        IF L1_1(#J)=700000 F1=1.  /*SOLOLÁ.
> -                        IF L1_1(#K)>=700001 and L1_1(#K)<=719001 F2=1.
>  /* MUNICIPÍOS SANTA ROSA.
> -                        IF L1_1(#J)=800000 F1=1.  /*TOTONICAPÁN.
> -                        IF L1_1(#K)>=801000 and L1_1(#K)<=807000 F2=1.
>  /* MUNICIPÍOS TOTONICAPAN.
> -                        IF L1_1(#J)=900000 F1=1.  /*QUETZALTENANGO.
> -                        IF L1_1(#K)>=900001 and L1_1(#K)<=940000 F2=1.
>  /* MUNICIPÍOS QUETZALTENANGO.
> -                        IF L1_1(#J)=1000000 F1=1.  /*SUCHITEPEQUEZ.
> -                        IF L1_1(#K)>=1001001 and L1_1(#K)<=1021000 F2=1.
> /* MUNICIPOÍOS SUCHITEPEQUEZ.
> -                        IF L1_1(#J)=1100000 F1=1.  /*RETALHULEU.
> -                        IF L1_1(#K)>=1100001 and L1_1(#K)<=1108001 F2=1.
> /* MUNICIPIOS RETALHULEU.
> -                        IF L1_1(#J)=1200000 F1=1.  /*SAN MARCOS.
> -                        IF L1_1(#K)>=1200001 and L1_1(#K)<=1290001 F2=1.
> /* MUNICIPÍOS SAN MARCOS.
> -                        IF L1_1(#J)=1301000 F1=1.  /*HUEHUETENANGO.
> -                        IF L1_1(#K)>=1301001 and L1_1(#K)<=1331000 F2=1.
> /* MUNICIPÍOS HUEHUETENANGO.
> -                        IF L1_1(#J)=1401000 F1=1.  /*QUICHÉ.
> -                        IF L1_1(#K)>=1402000 and L1_1(#K)<=1419000 F2=1.
> /*MUNICIPIOS QUICHÉ.
> -                        IF L1_1(#J)=1501000 F1=1.  /*BAJA VERAPAZ.
> -                        IF L1_1(#K)>=1502000 and L1_1(#K)<=1508001 F2=1.
> /* MUNICIPIOS BAJA VERAPAZ.
> -                        IF L1_1(#J)=1600000 F1=1.   /*ALTA VERAPAZ.
> -                        IF L1_1(#K)>=1600001 and L1_1(#K)<=1617000 F2=1.
> /*MUNICIPIOS ALTA VERAPAZ.
> -                        IF L1_1(#J)=1700000 F1=1.   /*PETÉN.
> -                        IF L1_1(#K)>=1700001 and L1_1(#K)<=1713001 F2=1.
>  /*MUNICIPÍOS PETÉN.
> -                        IF L1_1(#J)=1800000 F1=1.   /*IZABAL.
> -                        IF L1_1(#K)>=1800001 and L1_1(#K)<=1805005 F2=1.
>  /*MUNICIPÍOS IZABAL.
> -                        IF L1_1(#J)=1900000 F1=1.  /*ZACAPA.
> -                        IF L1_1(#K)>=1900001 and L1_1(#K)<=1910000 F2=1.
>  /* MUNICIPÍOS ZACAPA.
> -                        IF L1_1(#J)=2000000 F1=1.  /*CHIQUIMULA.
> -                        IF L1_1(#K)>=2000001 and L1_1(#K)<=2010000 F2=1.
>  /* MUNICIPÍOS CHIQUIMULA.
> -                        IF L1_1(#J)=2100000 F1=1.   /*JALAPA.
> -                        IF L1_1(#K)>=2100001 and L1_1(#K)<=2106003 F2=1.
>  /*MUNICIPÍOS JALAPA.
> -                        IF L1_1(#J)=2200000 F1=1.   /*JUTIAPA.
> -                        IF L1_1(#K)>=2200001 and L1_1(#K)<=2215000 F2=1.
>  /* MUNICIPÍOS JUTIAPA.
> -                        IF (F1=1 and F2=1) repetido=(L1_1(#J)).
> -                           compute #y=#y+1.
> -                           compute y(#y)=L1_1(#K).  /*COPIA DE DATOS
> ORIGINALES.
> -                     END LOOP.
> -                     DO IF F1=1 and F2=1.
> -                          PRINT / 'Número Cuest.' Correlativo1 ' Códigos
> duplicados ---> ' repetido '  SET de códigos ---> '  Lugar1_1_Cod TO
> Lugar1_12_Cod. /*LISTA DE ERRORES.
> -                     END IF.
> -         END IF.
> END LOOP.
> EXECUTE.
>
> /* MACRO PARA ELIMINACION DE CODIGOS REPETIDOS o marca madre.
> define duble (!positional= !charend('|')
>  /zm =!default(miss) !charend('|')) .
> !let !ciag=''.
> !let !jeden=''.
> !let !dwa=''.
> recode !1 (0=sysmis).
> !do !i !in (!1).
> !let !jeden=(!i).
> !do !j !in (!1).
> !let !dwa=(!j).
> !if (!jeden<>!dwa) !then
> if (!i=!j) !j=$sysmis.
> !ifend.
> !doend.
> !doend.
> !do !i !in (!1).
> !let !ciag=!concat(!ciag,',',!i).
> !doend.
> !let !ciag=!tail(!ciag).
> if (nvalid(!ciag)=0) !zm=0.
> value labels /!zm 0'missing case'.
> !enddefine.
> *example remplazo en variables originales.
> duble repetido Lugar1_1_Cod Lugar1_2_Cod Lugar1_3_Cod Lugar1_4_Cod
> Lugar1_5_Cod Lugar1_6_Cod Lugar1_7_Cod Lugar1_8_Cod Lugar1_9_Cod
> Lugar1_10_Cod Lugar1_11_Cod Lugar1_12_Cod.
> EXECUTE.
>
>
> I know that this process can be generated in many ways, if you would like
> to contribute or facilitate the process the suggestions will be welcome.
>
> Many thanks again to this community of SPSS experts for their time.
>
> regards
>
>
> El vie., 29 mar. 2019 a las 14:21, Art Kendall (&lt;

> Art@

> &gt;)
> escribió:
>
>> Is it correct to assume that a department is a wider geographic/political
>> unit and sites are more specific geographically withing a department?
>>
>> Do the 4 least significant digits (rightmost characters) always designate
>> a
>> site, and the 2 or 3 most significant digits designate the department?
>>
>>
>>
>>
>>
>>
>> -----
>> 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
>>

> 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





--
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: Replace data in multiple mention (different variables)

PRogman
Javier, please indicate what the correct output would be /for each/ of your 5
demonstration data cases.



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