3

I have a long syntax (1800 lines) and this one portion has been giving me trouble. I can't for the life of me figure out what I'm doing incorrectly.

It is supposed to take an existing file and narrow it down to just the variables listed in the /KEEP statement. Then every variable is renamed to a similar variable name, but "oldxxxx". Later my syntax matches the new file to this updated variable file and points out any changes in the values, giving a list of reasons in the recoded file.

Once the syntax reaches the first RENAME VARIABLES I get the following error:

RENAME VARIABLES Duplicate variable names from RENAME.

Thank you in advance!

Michael H
  • 31
  • 5
  • 1
    The SAVE command does not alter the active dataset, it only drops some variables from the new sav file it creates. If you run something like `ADD FILES FILE = * /KEEP [VARS HERE].`, placing the same variables on the `KEEP` subcommand and then `EXECUTE.` you active dataset should have the same variables as the saved file. – Andy W Dec 06 '16 at 20:37
  • You can make the syntax clearer by using the DELETE VARIABLES command, which operates on the active file. – JKP Dec 07 '16 at 22:53
  • I would suggest you to use `GET FILE='LastAwardingFile.sav(or newfilename. sav) '. DATASET NAME LastAwardingFile WINDOW=FRONT.` again just before the first `RENAME VARIABLES... ` but this should overwrite if old file name is used. – rawatdeepesh Dec 21 '16 at 01:40

2 Answers2

2

First a couple of remarks: It would be better practice to save to a different file name. In your syntax the original file gets saved over and you can't go back... Also I recommend you follow @Andy W's advice regarding how to keep only the variables you need in your file.

Now, in the sample syntax you posted I see an error - possibly that's your problem:

RENAME VARIABLES (total_EMFASYS_award=oldgrant).

The new name is oldgrant instead or oldtotal_EMFASYS_award. Possibly further down you've got another command saying

RENAME VARIABLES (grant=oldgrant).

hence the double name.

To avoid such errors and shorten your syntax, you could use the following macro:

define renVars (!pos=!cmdend)
rename variables 
!do !i !in (!1) !i = !concat("old",!i)
!doend .
!enddefine.

After running this macro definition you can run the macro by stating the macro name and the full list of variables you want renamed, like this:

renVars 
Student_ID rl_highschoolgpa comb need qualitygrp NewUpfrontGrant meritgrant 
targetcounty_housing housinggrant  tuitiongrant athlete_recruit .
eli-k
  • 10,898
  • 11
  • 40
  • 44
2

One thing to note about RENAME VARIABLES command - it also works like this:

RENAME VARIABLES (list_of_starting_variable_names = list_of_final_variable_names).

you would just need to provide the 2 names lists, and the renaming will be done in th eorder in which the names are provided (1st variable in list 1 gets renamed to the 1st variable in list 2,... n-th variable in list 1 into the n-th variable in list 2... and so on.

This should avoid the Duplicate Variable Names error you are getting, as all renames are done in one go. But would require you to alter the original syntax a bit, and is a bit harder to spot which variable gets renamed into which variable.

horace_vr
  • 3,026
  • 6
  • 26
  • 48