|
Hi,
Do any of you know whether it is possible to automatically change a variable name in a syntax file? Find and replace would not work because the variable name could appear in another context, such as a variable label, where you might not want to change it. Let's say I have a file with a variable named "date" and I want to change it to "date2," but only where it's an actual variable name, and is not part of some label or something else (where you might have the word "date" as part of the phrase "date of birth"). I am asking this question for a colleague who says that in SAS she can write some code at the beginning of a file, and specify what to change at the beginning without having to manually go through the entire file finding and replacing. Is this possible in SPSS? Thanks, Miriam |
|
Hi Miriam,
The RENAME VARIABLES command will change the variable name. It has no effect on value or variable labels. RENAME VARIABLES date = date2. You can change the names of multiple variables with the same command: RENAME VARIABLES (date = date2) (address = address2) (lname = lname2). The command takes effect immediately and doesn't require an EXE to refresh the data window. Hope this helps, Dan R. Miriam L. Gerver wrote: > Hi, > > Do any of you know whether it is possible to automatically change a > variable name in a syntax file? Find and replace would not work > because the variable name could appear in another context, such as a > variable label, where you might not want to change it. Let's say I > have a file with a variable named "date" and I want to change it to > "date2," but only where it's an actual variable name, and is not part > of some label or something else (where you might have the word "date" > as part of the phrase "date of birth"). > > I am asking this question for a colleague who says that in SAS she can > write some code at the beginning of a file, and specify what to change > at the beginning without having to manually go through the entire file > finding and replacing. Is this possible in SPSS? > > Thanks, > Miriam > -- Daniel Robertson Senior Research and Planning Associate Institutional Research and Planning Cornell University, Ithaca NY 14853-2801 607.255.9642 / irp.cornell.edu |
|
In reply to this post by Miriam L. Gerver
As far as I know, and considering that syntax files are plain text
files, you cannot distinguish words according to their syntactical function as variable names, labels, comments or whatever. You'd have to proceed by "find next" and "replace" instead of "replace all". In my case, I once had to deal with such a problem and solved it by using a special character as the first character for variable names (@), so that "@date" could not possibly be confused with "date"). Of course that begs the question: how you change the name of the variable IN THE SYNTAX FILE if the latter is already done; well, I do not know. I did it beforehand, naming the variables that way from the beginning, before I started updating their names. Often my variables have codified names that hardly appear in any other function, such as Q_18_1, or unlikely compound words such as "incomesource" or "dateofbirth" so I do not have to worry. Hector -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Miriam L. Gerver Sent: 23 July 2007 13:30 To: [hidden email] Subject: automatically changing/updating variable name Hi, Do any of you know whether it is possible to automatically change a variable name in a syntax file? Find and replace would not work because the variable name could appear in another context, such as a variable label, where you might not want to change it. Let's say I have a file with a variable named "date" and I want to change it to "date2," but only where it's an actual variable name, and is not part of some label or something else (where you might have the word "date" as part of the phrase "date of birth"). I am asking this question for a colleague who says that in SAS she can write some code at the beginning of a file, and specify what to change at the beginning without having to manually go through the entire file finding and replacing. Is this possible in SPSS? Thanks, Miriam |
|
In reply to this post by Daniel Robertson
Sorry, I think I read your message too quickly and provided an unhelpful
answer. If you're asking whether it is possible to use the SPSS Syntax Editor to find/replace certain words in the syntax file only when they refer to variable names, then as far as I no there is no way to do that. A syntax file is just a plain text file and it contains no meta-level coding -- there is nothing in the syntax file that identifies a variable name as a variable name (or as anything else) other than the context in which it occurs in the code. But given that limitation, there are any number of freely available text editors that allow more complex search/replace functionality than the SPSS Syntax editor, such as Notepad++ or TextPad. Sorry for the misunderstanding, hope this helps, Dan R. Daniel Robertson wrote: > Hi Miriam, > > The RENAME VARIABLES command will change the variable name. It has no > effect on value or variable labels. > > RENAME VARIABLES date = date2. > > You can change the names of multiple variables with the same command: > > RENAME VARIABLES (date = date2) (address = address2) (lname = lname2). > > The command takes effect immediately and doesn't require an EXE to > refresh the data window. > > Hope this helps, > > Dan R. > > Miriam L. Gerver wrote: >> Hi, >> >> Do any of you know whether it is possible to automatically change a >> variable name in a syntax file? Find and replace would not work >> because the variable name could appear in another context, such as a >> variable label, where you might not want to change it. Let's say I >> have a file with a variable named "date" and I want to change it to >> "date2," but only where it's an actual variable name, and is not part >> of some label or something else (where you might have the word "date" >> as part of the phrase "date of birth"). >> >> I am asking this question for a colleague who says that in SAS she can >> write some code at the beginning of a file, and specify what to change >> at the beginning without having to manually go through the entire file >> finding and replacing. Is this possible in SPSS? >> >> Thanks, >> Miriam >> > -- Daniel Robertson Senior Research and Planning Associate Institutional Research and Planning Cornell University, Ithaca NY 14853-2801 607.255.9642 / irp.cornell.edu |
|
In reply to this post by Daniel Robertson
This advice is about changing the variable names themselves, not
about changing the words designating variable names in a SYNTAX FILE, which is what the question was about. Even after changing the name of a variable with RENAME VARIABLE, you are still stuck with syntax files full of references to the old name. Hector -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Daniel Robertson Sent: 23 July 2007 13:53 To: [hidden email] Subject: Re: automatically changing/updating variable name Hi Miriam, The RENAME VARIABLES command will change the variable name. It has no effect on value or variable labels. RENAME VARIABLES date = date2. You can change the names of multiple variables with the same command: RENAME VARIABLES (date = date2) (address = address2) (lname = lname2). The command takes effect immediately and doesn't require an EXE to refresh the data window. Hope this helps, Dan R. Miriam L. Gerver wrote: > Hi, > > Do any of you know whether it is possible to automatically change a > variable name in a syntax file? Find and replace would not work > because the variable name could appear in another context, such as a > variable label, where you might not want to change it. Let's say I > have a file with a variable named "date" and I want to change it to > "date2," but only where it's an actual variable name, and is not part > of some label or something else (where you might have the word "date" > as part of the phrase "date of birth"). > > I am asking this question for a colleague who says that in SAS she can > write some code at the beginning of a file, and specify what to change > at the beginning without having to manually go through the entire file > finding and replacing. Is this possible in SPSS? > > Thanks, > Miriam > -- Daniel Robertson Senior Research and Planning Associate Institutional Research and Planning Cornell University, Ithaca NY 14853-2801 607.255.9642 / irp.cornell.edu |
| Free forum by Nabble | Edit this page |
