APPLY DICTIONARY

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

APPLY DICTIONARY

Jignesh Sutar
Can apply dictionary syntax be used to copy more than one source data
variable?

ie x1 copied to y1
   x2 copied to y2...ect

Thanks in advance
Jignesh
Reply | Threaded
Open this post in threaded view
|

Re: APPLY DICTIONARY

ViAnn Beadle
Yes. Go to Help select APPLY DICTIONARY from the Index Tab. You'll find a
topic called Source and Target Subcommands with a mapping table.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of J
Sutar
Sent: Tuesday, June 12, 2007 10:02 AM
To: [hidden email]
Subject: APPLY DICTIONARY

Can apply dictionary syntax be used to copy more than one source data
variable?

ie x1 copied to y1
   x2 copied to y2...ect

Thanks in advance
Jignesh
Reply | Threaded
Open this post in threaded view
|

Re: APPLY DICTIONARY

Peck, Jon
In reply to this post by Jignesh Sutar
APPLY DICTIONARY can map when the names are identical in the two datasets, but you cannot specify both explicit sources and explicit targets as in x1 -> y1 and x2 -> y2.

You could do this with programmability by generating multiple apply dictionary commands.

HTH,
Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of J Sutar
Sent: Tuesday, June 12, 2007 11:02 AM
To: [hidden email]
Subject: [SPSSX-L] APPLY DICTIONARY

Can apply dictionary syntax be used to copy more than one source data
variable?

ie x1 copied to y1
   x2 copied to y2...ect

Thanks in advance
Jignesh
Reply | Threaded
Open this post in threaded view
|

AW: Re: APPLY DICTIONARY

Georg Maubach
Hi Jegnesh,

we use a macro to fulfil this task which is part of our CONCERTO Macro Library System. You can specify as many source variables as you like. The macro takes a list of source variables and target variables and iterates over both lists in parallel.

If you have variables called x1 TO x10 and want to copy variable labels to variables named y1 TO y10 you call the macro like this:

@CopyVarLab sbase = 'x'
            tbase = 'y'
            no    = 10 .

The macro is documented. Please feel free to ask should any question arise.

Just in case it is useful to you I include the macro that copies value labels.

At this time I would like to say thank you to all who contribute to this list and have helped me to learn a lot and develop the code we need for our projects and helped us to build the CONCERTO Macro Library System.

HTH

Georg Maubach

/* [ Name ] ------------------------------------------------*/.
/* CopyVarLab (COPY VARiable LABel)
/*
/* [ Status ] ----------------------------------------------*/.
/* Author      : Georg Maubach (MRSC)
/* Last Editor : Georg Maubach (MRSC)
/* Date        : 24-Jul-2005
/* Modified    : 19-APR-2006
/* Status      : released
/* Version     : 2
/* Release     : 1
/*
/* [ Platform ] ---------------------------------------------*/.
/* Source System : SPSS (Win), Rel.13.0.1 (20 Nov 2004)
/* Target System : SPSS (Win), Rel.11
/*
/* [ Description ] -----------------------------------------*/.
/* The macro copies the variable label of one source variable
/* to multiple target variables using a number to give the
/* number of variables the variable label shall be copied to.
/* The macro extends the SPSS command APPLY DICTIONARY with
/* the ability to copy variable labels from many source
/* variables to many target variables.
/*
/* [ Parameter ] -------------------------------------------*/.
/* sbase    (quoted)   = name of base of source variable
/* tbase    (quoted)   = name of base of target variable
/* no       (unquoted) = number of offset variables
/*
/* [ Result ] -----------------------------------------------*/.
/* The target variables have the variable labels of the source
/* variables.
/*
/* [ Operation ] --------------------------------------------*/.
/* The macro uses a fixed variable format and a number to
/* derive the variable names. The number is used as a counter
/* to run through the variable list.
/*
/* [ Call ] -------------------------------------------------*/.
/* @CopyVarLab sbase = 'q10.' tbase = 'r10.' no = 15 .
/*
/* [ Example ] ----------------------------------------------*/.
/* The source variables "q10.01 - q10.15" are continuous
/* variables which shall be copied to "c10.01 to c10.15" to
/* recode them into categorial variables. The new variables
/* shall all get the variable labels of the source variables.
/*
/* The SPSS command APPLY DICTIONARY could only copy the var-
/* iable label from one source variable to multiple target
/* variables. In the above given example from "q10.01" to
/* "r10.01 - r10.15" but this would not be intended.
/*
/* [ Release Notes ] ----------------------------------------*/.
/* None.
/*
/*----------1---------2---------3---------4---------5--------6*/.

DEFINE @CopyVarLab (sbase !TOKENS(1)
                   /tbase !TOKENS(1)
                   /no    !TOKENS(1)).

!IF (!BLANKS(!no) !LT !BLANKS(10))
     !THEN
          !DO !counter = 1 !TO !no
              APPLY DICTIONARY FROM *
                 /SOURCE VARIABLES=!CONCAT(!UNQUOTE(!EVAL(!sbase)),'0',!counter)
                 /TARGET VARIABLES=!CONCAT(!UNQUOTE(!EVAL(!tbase)),'0',!counter) /VARINFO VARLABEL.
          !DOEND
     !IFEND

!IF (!BLANKS(!no) !GT !BLANKS(10))
     !THEN
          !DO !counter = 1 !TO 9
              APPLY DICTIONARY FROM *
                 /SOURCE VARIABLES=!CONCAT(!UNQUOTE(!EVAL(!sbase)),'0',!counter)
                 /TARGET VARIABLES=!CONCAT(!UNQUOTE(!EVAL(!tbase)),'0',!counter) /VARINFO VARLABEL.
          !DOEND

          !DO !counter = 10 !TO !no
              APPLY DICTIONARY FROM *
                 /SOURCE VARIABLES=!CONCAT(!UNQUOTE(!EVAL(!sbase)),!counter)
                 /TARGET VARIABLES=!CONCAT(!UNQUOTE(!EVAL(!tbase)),!counter) /VARINFO VARLABEL.
          !DOEND
     !IFEND

EXECUTE.

!ENDDEFINE.

/* [Name ] -----------------------------------------------*/.
/* CopyValLab (COPY VALue LABel)
/*
/* [ Status ] --------------------------------------------*/.
/* Author   : Georg Maubach (MRSC)
/* Date     : 24-Jul-2005
/* Status   : released
/* Version  : 1
/* Release  : 1
/*
/* [ Description ] ---------------------------------------*/.
/* The macro copies the value label from a target variable
/* to a source variable using a counter to compute the off-
/* set of the target variable.
/*
/* The macro is useful if the number of variables is given
/* in a macro and is used for a hole bunch of variables
/* having all the same number of items. It is also useful
/* if number of variables stored in the macro is derived
/* from the data using syntax.
/* Without using the number of variables it would be
/* necessary to hand over a complete list of target
/* variables.
/*
/* [ Parameter ] -----------------------------------------*/.
/* sbase    (quoted)   = name of base of source variable
/* tbase    (quoted)   = name of base of target variable
/* no       (unquoted) = number of offset variables
/*
/* [ Result ] --------------------------------------------*/.
/* Copied value labels.
/*
/* [ Operation ] -----------------------------------------*/.
/* The value label from the source variable is copied to
/* all other target variables where the number of offset
/* variables is given by the parameter "no".
/*
/* The macro is based on a variable format q01.01 for base
/* and offset.
/*
/* [ Example ] -------------------------------------------*/.
/* DEFINE @no () 15 !ENDDEFINE .
/*
/* If the source variable is q10.01 with value labels
/*
/* 1 = 'very good'
/* 2 = 'indifferent'
/* 3 = 'very bad'
/*
/* the macro call
/*
/* @CopyValLab sbase = 'q10.' tbase = 'r10.' no = @no .
/*
/* copies the value labels of variable "q10.01" to the var-
/* iables "r10.01 - r10.15'.
/*
/* The macro could also be used to copy the value labels
/* from one source variable to the same bunch of variables
/* like
/*
/* @CopyValLab sbase = 'q10.' tbase = 'q10.' no = 15 .
/*
/* so that the VALUE LABEL command can be applied to only
/* one variable and be copied to all associated variables.
/*
/* [ Release Notes ] -------------------------------------*/.
/* None.
/*--------1---------2---------3---------4---------5-------*/.

DEFINE @CopyValLab (sbase !CHAREND('/')
                   /tbase !CHAREND('/')
                   /no    !CMD).

!IF (!BLANKS(!no) !LT !BLANKS(10))
     !THEN
          !DO !counter = 2 !TO !no
              APPLY DICTIONARY FROM *
                 /SOURCE VARIABLES=!CONCAT(!UNQUOTE(!sbase),'01')
                 /TARGET VARIABLES=!CONCAT(!UNQUOTE(!tbase),'0',!counter) /VARINFO VALLABELS=REPLACE.
          !DOEND
     !IFEND

!IF (!BLANKS(!no) !GT !BLANKS(10))
     !THEN
          !DO !counter = 2 !TO 9.
              APPLY DICTIONARY FROM *
                 /SOURCE VARIABLES=!CONCAT(!UNQUOTE(!sbase),'01')
                 /TARGET VARIABLES=!CONCAT(!UNQUOTE(!tbase),'0',!counter) /VARINFO VALLABELS=REPLACE.
          !DOEND

          !DO !counter = 10 !TO !no.
              APPLY DICTIONARY FROM *
                 /SOURCE VARIABLES=!CONCAT(!UNQUOTE(!sbase),'01')
                 /TARGET VARIABLES=!CONCAT(!UNQUOTE(!tbase),!counter) /VARINFO VALLABELS=REPLACE.
          !DOEND
     !IFEND

EXECUTE.

!ENDDEFINE.

-----Ursprüngliche Nachricht-----
Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von Peck, Jon
Gesendet: Dienstag, 12. Juni 2007 23:03
An: [hidden email]
Betreff: Re: APPLY DICTIONARY

APPLY DICTIONARY can map when the names are identical in the two datasets, but you cannot specify both explicit sources and explicit targets as in x1 -> y1 and x2 -> y2.

You could do this with programmability by generating multiple apply dictionary commands.

HTH,
Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of J Sutar
Sent: Tuesday, June 12, 2007 11:02 AM
To: [hidden email]
Subject: [SPSSX-L] APPLY DICTIONARY

Can apply dictionary syntax be used to copy more than one source data variable?

ie x1 copied to y1
   x2 copied to y2...ect

Thanks in advance
Jignesh