I have some data with 3 string fields.
What I want to do is to create a new string variable
which is a concatenation of the three variables.
This will eventually become a label.
I then want to make the id field numeric.
After I create a numeric id field I wish to use
the concatenation field I created earlier into
a Value Label for the new ID field.
I am getting stuck on how to take the new IDLabel variable
and convert it's string values into value labels for the
NID variable.
Any ideas?
TIA,
Lance
data list list / fname (A5) lname (A10) id (A10).
begin data
"Beth" "Jones" 11960 .
"Bob" "Jensen" 21965
"Barb" "Andersen" 31954
"Andy" "Smith" 41926
"Al" "Peterson" 51921
"Ann" "Glenn" 61922
"Pete" "." 71969
"Pam" "Wright" 81952
"Phil" "Brown" 91959
end data.
STRING IDLABEL (A80).
COMPUTE IDLABEL = CONCAT(FNAME," ",LNAME," (",ID,")").
COMPUTE NID = NUMERIC(ID,F6).
EXE.
Example of what I want next:
Value Labels NID
11960 = "Beth Jones (11960)".
|
|
0
|
|
|
|
Reply
|
lance-news (7)
|
2/17/2010 5:00:52 PM |
|
On Feb 17, 12:00=A0pm, Lance Hoffmeyer <lance-n...@augustmail.com>
wrote:
> I have some data with 3 string fields.
>
> What I want to do is to create a new string variable
> which is a concatenation of the three variables.
> This will eventually become a label.
>
> I then want to make the id field numeric.
>
> After I create a numeric id field I wish to use
> the concatenation field I created earlier into
> a Value Label for the new ID field.
>
> I am getting stuck on how to take the new IDLabel variable
> and convert it's string values into value labels for the
> NID variable.
>
> Any ideas?
>
> TIA,
>
> Lance
>
> data list list / fname (A5) lname (A10) id (A10).
> begin data
> "Beth" "Jones" 11960 .
> "Bob" "Jensen" 21965
> "Barb" "Andersen" 31954
> "Andy" "Smith" 41926
> "Al" "Peterson" 51921
> "Ann" "Glenn" 61922
> "Pete" "." 71969
> "Pam" "Wright" 81952
> "Phil" "Brown" 91959
> end data.
>
> STRING IDLABEL (A80).
> COMPUTE IDLABEL =3D CONCAT(FNAME," ",LNAME," (",ID,")").
> COMPUTE NID =3D NUMERIC(ID,F6).
> EXE.
I think your IDLABEL variable will be a bit neater if you include a
few RTRIMs, like this:
COMPUTE IDLABEL =3D CONCAT(rtrim(FNAME),"
",rtrim(LNAME)," (",rtrim(ID),")").
>
> Example of what I want next:
>
> Value Labels NID
> =A0 =A011960 =3D "Beth Jones (11960)".
You could write a series of ADD VALUE LABELS commands out to a file,
and then include it via INCLUDE (or INSERT) file. E.g.,
write outfile =3D "C:\temp\val labels.txt" /
"add val lab nid ",nid, ' "', idlabel,'" .' .
exe.
include file =3D "C:\temp\val labels.txt" .
ADD VALUE LABELS does not remove any already existing value labels, as
does VALUE LABELS without the "ADD".
HTH.
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/Home
"When all else fails, RTFM."
|
|
0
|
|
|
|
Reply
|
Bruce
|
2/17/2010 7:04:56 PM
|
|
On Feb 17, 12:04=A0pm, Bruce Weaver <bwea...@lakeheadu.ca> wrote:
> On Feb 17, 12:00=A0pm, Lance Hoffmeyer <lance-n...@augustmail.com>
> wrote:
>
>
>
> > I have some data with 3 string fields.
>
> > What I want to do is to create a new string variable
> > which is a concatenation of the three variables.
> > This will eventually become a label.
>
> > I then want to make the id field numeric.
>
> > After I create a numeric id field I wish to use
> > the concatenation field I created earlier into
> > a Value Label for the new ID field.
>
> > I am getting stuck on how to take the new IDLabel variable
> > and convert it's string values into value labels for the
> > NID variable.
>
> > Any ideas?
>
> > TIA,
>
> > Lance
>
> > data list list / fname (A5) lname (A10) id (A10).
> > begin data
> > "Beth" "Jones" 11960 .
> > "Bob" "Jensen" 21965
> > "Barb" "Andersen" 31954
> > "Andy" "Smith" 41926
> > "Al" "Peterson" 51921
> > "Ann" "Glenn" 61922
> > "Pete" "." 71969
> > "Pam" "Wright" 81952
> > "Phil" "Brown" 91959
> > end data.
>
> > STRING IDLABEL (A80).
> > COMPUTE IDLABEL =3D CONCAT(FNAME," ",LNAME," (",ID,")").
> > COMPUTE NID =3D NUMERIC(ID,F6).
> > EXE.
>
> I think your IDLABEL variable will be a bit neater if you include a
> few RTRIMs, like this:
>
> COMPUTE IDLABEL =3D CONCAT(rtrim(FNAME),"
> ",rtrim(LNAME)," (",rtrim(ID),")").
>
>
>
> > Example of what I want next:
>
> > Value Labels NID
> > =A0 =A011960 =3D "Beth Jones (11960)".
>
> You could write a series of ADD VALUE LABELS commands out to a file,
> and then include it via INCLUDE (or INSERT) file. =A0E.g.,
>
> write outfile =3D "C:\temp\val labels.txt" /
> =A0"add val lab nid ",nid, ' "', idlabel,'" .' .
> exe.
>
> include file =3D "C:\temp\val labels.txt" .
>
> ADD VALUE LABELS does not remove any already existing value labels, as
> does VALUE LABELS without the "ADD".
>
> HTH.
>
> --
> Bruce Weaver
> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/Home
> "When all else fails, RTFM."
You could come pretty close just by using AUTORECODE. But take a look
at the function
genValueLabels in the spssaux2.py module from SPSS Developer Central.
It makes the values of a string variable into value labels for another
variable.
Here is the docstring from the function.
def genValueLabels(targetvar, labelvar, vardict=3DNone):
"""Generate value labels for targetvar from contents of labelvar.
Return conflict state.
targetvar is any existing variable.
labelvar is a variable whose values should be used to label the
values of targetvar.
vardict is an optional spssaux.VariableDict object containing at
least targetvar.
If there are conflicting values, the last one encountered wins.
If there are no conflicts, return value is True; if any conflicts,
value is False
System missing values are not labeled.
HTH,
Jon Peck
|
|
0
|
|
|
|
Reply
|
JKPeck
|
2/17/2010 11:52:39 PM
|
|
|
2 Replies
1621 Views
(page loaded in 0.404 seconds)
|