Hello,
I'm trying to transform/merge data from 2 different files. I have one data file where I have IDs and names among other things. I have another file where I have data with only IDs. I would like to replace the IDs in the 2nd dataset with the corresponding names. Name dataset Var_ID Var_Name Var_Location AB1234 J. Smith GA TY6789 S. Ryan ID YZ3421 L. Davis IL ...... ......... ....... Hierarcy dataset Employee_ID Supervisor1 Supervisor2 Supervisor3 HJKU77 AB1234 HJL677 SD1234 455633 AB1234 GHHJ67 YZ3421 TY5678 TY6789 RF5674 234FR3 .......... ..... ..... ........ What I need in the end is a hierarchy dataset which looks like this: Hierarchy names Employee_ID Supervisor1 Supervisor2 Supervisor3 HJKU77 J. Smith ....... .... 455633 J. Smith ........ L.Davis TY5678 S. Ryan ...... .... .......... ..... ...... ........ Thank you! |
get file=file with IDs only.
sort cases by var_id. dataset name one. get file=file with IDs and names. sort cases by var_id. dataset name two. match files file=* /file=two /keep var_name /by var_id. execute. At that point both files now have both names and IDs. You can then delete var_id from the active file if you want. Not tested, but I think it's correct. Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: j_pav <[hidden email]> To: [hidden email], Date: 03/14/2014 09:51 AM Subject: recoding variables using data from another file Sent by: "SPSSX(r) Discussion" <[hidden email]> Hello, I'm trying to transform/merge data from 2 different files. I have one data file where I have IDs and names among other things. I have another file where I have data with only IDs. I would like to replace the IDs in the 2nd dataset with the corresponding names. Name dataset Var_ID Var_Name Var_Location AB1234 J. Smith GA TY6789 S. Ryan ID YZ3421 L. Davis IL ...... ......... ....... Hierarcy dataset Employee_ID Supervisor1 Supervisor2 Supervisor3 HJKU77 AB1234 HJL677 SD1234 455633 AB1234 GHHJ67 YZ3421 TY5678 TY6789 RF5674 234FR3 .......... ..... ..... ........ What I need in the end is a hierarchy dataset which looks like this: Hierarchy names Employee_ID Supervisor1 Supervisor2 Supervisor3 HJKU77 J. Smith ....... .... 455633 J. Smith ........ L.Davis TY5678 S. Ryan ...... .... .......... ..... ...... ........ Thank you! -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/recoding-variables-using-data-from-another-file-tp5724879.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 |
Administrator
|
You should test that Rick;)
----- Need to go WIDE to LONG, MATCH to TABLE then back to WIDE (You might consider retaining long format?) Anyway, easy peasy. --- DATASET ACTIVATE name_dataset. SORT CASES BY Var_ID. DATASET ACTIVATE Hierarchy_dataset . VARSTOCASES / MAKE Var_ID FROM Supervisor1 TO Supervisor3 / INDEX=Super(Var_ID) . SORT CASES BY Var_ID. MATCH FILES FILE * / TABLE name_dataset BY Var_ID. SORT CASES BY Employee_ID. /* Optional IMNSHO */. CASESTOVARS ID=Employee_ID / INDEX=Super /DROP Var_ID.
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?" |
Oops. I didn't look at the differences
in the data structure.
Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: David Marso <[hidden email]> To: [hidden email], Date: 03/14/2014 10:56 AM Subject: Re: recoding variables using data from another file Sent by: "SPSSX(r) Discussion" <[hidden email]> You should test that Rick;) ----- Need to go WIDE to LONG, MATCH to TABLE then back to WIDE (You might consider retaining long format?) Anyway, easy peasy. --- DATASET ACTIVATE name_dataset. SORT CASES BY Var_ID. DATASET ACTIVATE Hierarchy_dataset . VARSTOCASES / MAKE Var_ID FROM Supervisor1 TO Supervisor3 / INDEX=Super(Var_ID) . SORT CASES BY Var_ID. MATCH FILES FILE * / TABLE name_dataset BY Var_ID. SORT CASES BY Employee_ID. /* Optional IMNSHO */. CASESTOVARS ID=Employee_ID / INDEX=Super /DROP Var_ID. Rick Oliver wrote > get file=file with IDs only. > sort cases by var_id. > dataset name one. > get file=file with IDs and names. > sort cases by var_id. > dataset name two. > match files file=* /file=two /keep var_name /by var_id. > execute. > > At that point both files now have both names and IDs. You can then delete > var_id from the active file if you want. > > Not tested, but I think it's correct. > > Rick Oliver > Senior Information Developer > IBM Business Analytics (SPSS) > E-mail: > oliverr@.ibm > > > > From: j_pav < > jenny.pavlova@ > > > To: > SPSSX-L@.uga > , > Date: 03/14/2014 09:51 AM > Subject: recoding variables using data from another file > Sent by: "SPSSX(r) Discussion" < > SPSSX-L@.uga > > > > > > Hello, > I'm trying to transform/merge data from 2 different files. I have one data > file where I have IDs and names among other things. I have another file > where I have data with only IDs. I would like to replace the IDs in the > 2nd > dataset with the corresponding names. > > Name dataset > Var_ID Var_Name Var_Location > AB1234 J. Smith GA > TY6789 S. Ryan ID > YZ3421 L. Davis IL > ...... ......... ....... > > Hierarcy dataset > Employee_ID Supervisor1 Supervisor2 Supervisor3 > HJKU77 AB1234 HJL677 SD1234 > 455633 AB1234 GHHJ67 YZ3421 > TY5678 TY6789 RF5674 234FR3 > .......... ..... ..... > ........ > > What I need in the end is a hierarchy dataset which looks like this: > > Hierarchy names > Employee_ID Supervisor1 Supervisor2 Supervisor3 > HJKU77 J. Smith ....... .... > 455633 J. Smith ........ > L.Davis > TY5678 S. Ryan ...... .... > .......... ..... ...... > ........ > > Thank you! > > > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/recoding-variables-using-data-from-another-file-tp5724879.html > > Sent from the SPSSX Discussion mailing list archive at 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 ----- 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?" -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/recoding-variables-using-data-from-another-file-tp5724879p5724882.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 |
Free forum by Nabble | Edit this page |