Do-Repeat and Apply dictionary question

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

Do-Repeat and Apply dictionary question

Norberto Hernandez
Hello. I'm trying to create a new set of variables with a Do-Repeat command. When I use the Apply Dictionary for the metadata inside the do-repeat loop, I get the following error:


"Texto: newVar Comando: APPLY DICTIONARY
Se ha especificado un nombre de variable sin definir o una variable del sistema o temporal en una lista de variables que sólo acepta variables estándar.  Compruebe que dicha variable existe y que la ha escrito correctamente.
La ejecución de este comando se detiene.

La lista de variables después de TARGET está vacía. Para aplicar sólo atributos de nivel de archivo, utilice un subcomando VARINFO vacío."

It says that ist specified an undefined variable or a temporal or system variable in a variable list that only acepts standar variables. 

This is my code:

do repeat newVar = g02 to g24.
   compute newVar = g01.
   APPLY DICTIONARY FROM "Conjunto_de_datos1"
 /SOURCE VARIABLES = g01
 /TARGET VARIABLES = newVar.
end repeat.

Thank you very much
Reply | Threaded
Open this post in threaded view
|

Re: Do-Repeat and Apply dictionary question

Andy W
For your particular case you can specify one variable on the source and many variables on the target, so the DO REPEAT is not necessary. So below should work with your example:

APPLY DICTIONARY FROM "Conjunto_de_datos1"
 /SOURCE VARIABLES = g01
 /TARGET VARIABLES = g02 to g24.

If you look up the help on DO REPEAT only a certain number of commands are allowed, and APPLY DICTIONARY is not one of them.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Do-Repeat and Apply dictionary question

Rick Oliver-3
In reply to this post by Norberto Hernandez
If the intent is to create g02 through g24, and then apply the attributes of g1 to all of those:

NUMERIC g02 to g24 (f8.2).
APPLY DICTIONARY
  /FROM datasetname
  /SOURCE VARIABLES=g01.
  /TARGET VARIABLES=g02 to g24.

If you really want all the new variables to have the same values as the original variable, you can use COMPUTE within DO REPEAT to create those variables, but don't put APPLY DICTIONARY in the DO REPEAT block.

Note that "compute somevar=someothervar" does not retain the dictionary properties in the new variable.


Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        Norberto Hernandez <[hidden email]>
To:        [hidden email],
Date:        06/11/2014 11:59 AM
Subject:        Do-Repeat and Apply dictionary question
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hello. I'm trying to create a new set of variables with a Do-Repeat command. When I use the Apply Dictionary for the metadata inside the do-repeat loop, I get the following error:


"Texto: newVar Comando: APPLY DICTIONARY
Se ha especificado un nombre de variable sin definir o una variable del sistema o temporal en una lista de variables que sólo acepta variables estándar.  Compruebe que dicha variable existe y que la ha escrito correctamente.
La ejecución de este comando se detiene.

La lista de variables después de TARGET está vacía. Para aplicar sólo atributos de nivel de archivo, utilice un subcomando VARINFO vacío."

It says that ist specified an undefined variable or a temporal or system variable in a variable list that only acepts standar variables. 

This is my code:

do repeat newVar = g02 to g24.
   compute newVar = g01.
   APPLY DICTIONARY FROM "Conjunto_de_datos1"
 /SOURCE VARIABLES = g01
 /TARGET VARIABLES = newVar.
end repeat.

Thank you very much
Reply | Threaded
Open this post in threaded view
|

Re: Do-Repeat and Apply dictionary question

David Marso
Administrator
In reply to this post by Norberto Hernandez
APPLY DICTIONARY doesn't work inside a DO REPEAT!!!
You may have received a message to that effect?
---
This probably does what you intended the DO REPEAT to achieve?
-
<set up sandbox>
MATRIX.
SAVE (TRUNC(UNIFORM(100,1)*5)+1)/OUTFILE  "C:\test.sav"/VARIABLES g01.
END MATRIX.
GET FILE  "C:\test.sav".
VARIABLE LABELS g01 "test variable 1".
VALUE LABELS g01 1 'test 1' 2 'test 2' 3 'test 3' 4 'test 4' 5 'test 5'.
SAVE OUTFILE  "C:\test.sav".
NEW FILE.
DATASET CLOSE ALL.

MATRIX.
SAVE UNIFORM(100,1)/OUTFILE  */VARIABLES g01.
END MATRIX.
DATASET NAME result.
</sandbox>.
/******************************************************************/.
/*< Macro written by David Marso 06/11/2014 >*/
/*< Not to be reproduced, circulated, copied into user code without this header > */.
/*< In other words, don't use in your project without attribution!! >*/.
/*< Not to be reposted to any website without written permission >*/.
DEFINE !ApplyDictionary ( sourcefile !CHAREND ("/")/ sourcevar  !CHAREND ("/") / targetlist !CMDEND ).
!DO !V !IN (!targetlist).
COMPUTE !V  = !sourcevar.
APPLY DICTIONARY FROM !sourcefile /SOURCE VARIABLES = !sourcevar /TARGET VARIABLES = !V.
!DOEND
!ENDDEFINE.
/******************************************************************/.

!ApplyDictionary sourcefile "C:\test.sav"/ sourcevar g01/ targetlist g01 g02 g03 g04 g05 g06 g07 g08 g09 etc.
DISPLAY DICTIONARY.

Norberto Hernandez wrote
Hello. I'm trying to create a new set of variables with a Do-Repeat
command. When I use the Apply Dictionary for the metadata inside the
do-repeat loop, I get the following error:


"Texto: newVar Comando: APPLY DICTIONARY
Se ha especificado un nombre de variable sin definir o una variable del
sistema o temporal en una lista de variables que sólo acepta variables
estándar.  Compruebe que dicha variable existe y que la ha escrito
correctamente.
La ejecución de este comando se detiene.

La lista de variables después de TARGET está vacía. Para aplicar sólo
atributos de nivel de archivo, utilice un subcomando VARINFO vacío."

It says that ist specified an undefined variable or a temporal or system
variable in a variable list that only acepts standar variables.

This is my code:

do repeat newVar = g02 to g24.
   compute newVar = g01.
   APPLY DICTIONARY FROM "Conjunto_de_datos1"
 /SOURCE VARIABLES = g01
 /TARGET VARIABLES = newVar.
end repeat.

Thank you very much
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: Do-Repeat and Apply dictionary question

Norberto Hernandez
In reply to this post by Andy W
Thank you very much for all your comments. You are the best guys!!


2014-06-11 12:19 GMT-05:00 Andy W <[hidden email]>:
For your particular case you can specify one variable on the source and many
variables on the target, so the DO REPEAT is not necessary. So below should
work with your example:

APPLY DICTIONARY FROM "Conjunto_de_datos1"
 /SOURCE VARIABLES = g01
 /TARGET VARIABLES = g02 to g24.

If you look up the help on DO REPEAT only a certain number of commands are
allowed, and APPLY DICTIONARY is not one of them.



-----
Andy W
[hidden email]
http://andrewpwheeler.wordpress.com/
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Do-Repeat-and-Apply-dictionary-question-tp5726425p5726428.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: Do-Repeat and Apply dictionary question

Ruben Geert van den Berg
For cloning many variables (with their dictionaries) in one go, try this tool: http://www.spss-tutorials.com/clone-variables/.

It also works on a mix of numeric and string variables.

P.s. note that COMPUTE replaces user missing values by system missings whereas RECODE ... (ELSE=COPY) INTO ... copies system missings.