SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  Rename multiple variables

    Posted Wed March 03, 2021 02:39 AM

    I have a data file with more than 100 variables.

    I would like to automatically rename these variables.

    Old name: HEALTH_AU_NUM.2021

    New name: NAT_21_HEALTH_AU_NUM.

    I wonder if there is a loop that I can use to do so?






    #SPSSStatistics
    #Support
    #SupportMigration


  • 2.  RE: Rename multiple variables

    Posted Wed March 03, 2021 02:42 AM

    What is the exact renaming rule?

    You could put all these in one RENAME VARIABLES command, but you would have to create it manually. If you have a name pattern for old and new, I can produce a little bit of code to do this.






    #SPSSStatistics
    #Support
    #SupportMigration


  • 3.  RE: Rename multiple variables

    Posted Wed March 03, 2021 03:35 AM

    Thank you for replaying.

    All variables have the same pattern

    (CATEGORY_XX_XXX.YEAR)

    HEALTH_AU_NUM.2021 = NAT_21_HEALTH_AU_NUM

    I was thinking,

    1. Select everything before the '.' (HEALTH_AU_NUM) and save it as new1
    2. select everything after the '.' (2021) and trim it to just keep the last 2 digits new2=21
    3. then create new3=concatenate("NAT_", "new2", "_", "new1").
    4. and then rename variable oldvarname = new3.

    I do not how to properly execute this.

    Thank you.






    #SPSSStatistics
    #Support
    #SupportMigration


  • 4.  RE: Rename multiple variables

    Posted Wed March 03, 2021 03:38 AM

    I will look at this tomorrow






    #SPSSStatistics
    #Support
    #SupportMigration


  • 5.  RE: Rename multiple variables

    Posted Wed March 03, 2021 03:41 AM


  • 6.  RE: Rename multiple variables

    Posted Wed March 03, 2021 04:07 PM

    I'm not sure I've got exactly what you want, but I have some code. Send me an email (jkpeckSupport Member), and I'll send it back to you. This site might mess up the formatting.







    #SPSSStatistics
    #Support
    #SupportMigration