merging files and renaming automatically variables

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

merging files and renaming automatically variables

Hans-Christian Stahl
Dear all,



I want to merge 45 spss data files to one big spss file. Some variable names
appear in more than one data file, i.e. the variable "chemoth" appears in
data file number 2 and 5 and 9 and so on. Now, I want to rename all the
variables in each data file so that each variable in the merge file is
unique. Does somebody know a syntax-script so that SPSS renames the
variables automatically while it merges the files? I don't want to have to
type each variable in the syntax so as to rename it. I imagine it might be
possible that for instance each variable of a file is renamed automatically
with a syntax-script as follows:



"variable name" + "number of the data file" = "new variable name"  (i.e.
chemoth = chemoth2 and so on)



Is there a solution to the problem? Does anybody can help me with a
syntax-script?



That would be of great help.



Thanks in advance,

Christian Stahl



PS: for answers you may also mail to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: merging files and renaming automatically variables

Albert-Jan Roskam
Hi Christian,

Why would you do that? Isn't it inconvenient to have
such a wide file? And much more difficult to make
between-file comparisons?

Anyway, the following *untested* syntax might work. It
first adds all files, and creates a variable
'whatfile' to identify the file numbers. As a last
step, the file is transposed. Be sure to save your
work before applying this. I assumed that your files
are named 'file_1.sav' through 'file_45.sav'.

define blah ()
!let !myfile =
    !quote(!concat("d:\temp\file_",!cnt,".sav")).
!let !x = 1.
!do !cnt = 1 !to 45.
get = !myfile.
compute whatfile = !cnt.
!if (!x = 1) !then.
!let !x = 0.
save outfile = "d:\temp\myoutfile.sav".
!else.
add files / file = "d:\temp\myoutfile.sav" / file =
!myfile .
!ifend.
!doend.
save outfile = "d:\temp\myoutfile.sav".
casestovars / id = !cnt.
save outfile = "d:\temp\myoutfile_transposed.sav".
!enddefine.

set mprint = on.
blah.
set mprint = off.

Cheers!!
Albert-Jan

--- Hans-Christian Stahl
<[hidden email]> wrote:

> Dear all,
>
>
>
> I want to merge 45 spss data files to one big spss
> file. Some variable names
> appear in more than one data file, i.e. the variable
> "chemoth" appears in
> data file number 2 and 5 and 9 and so on. Now, I
> want to rename all the
> variables in each data file so that each variable in
> the merge file is
> unique. Does somebody know a syntax-script so that
> SPSS renames the
> variables automatically while it merges the files? I
> don't want to have to
> type each variable in the syntax so as to rename it.
> I imagine it might be
> possible that for instance each variable of a file
> is renamed automatically
> with a syntax-script as follows:
>
>
>
> "variable name" + "number of the data file" = "new
> variable name"  (i.e.
> chemoth = chemoth2 and so on)
>
>
>
> Is there a solution to the problem? Does anybody can
> help me with a
> syntax-script?
>
>
>
> That would be of great help.
>
>
>
> Thanks in advance,
>
> Christian Stahl
>
>
>
> PS: for answers you may also mail to
> [hidden email]
>


Cheers!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Did you know that 87.166253% of all statistics claim a precision of results that is not justified by the method employed? [HELMUT RICHTER]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


      ____________________________________________________________________________________
Shape Yahoo! in your own image.  Join our Network Research Panel today!   http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7