Dear list
I've been trying for a while now to add a "T2" to the variable names of a dataset. I have a dataset with 120 cases and about 300 variables. Now I'd like to rename v1, v2 .v300 into T2_v1, T2_v2 . T2_v300. Any idea on how to solve that with a neat little script? Philippe |
http://www.spsstools.net/Syntax/LabelsAndVariableNames/ChangeCharacterAt
BeginningOfEachVarNames.txt As per Raynalds website will give you the answer HtH Mike -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Philippe Rast Sent: 15 September 2006 14:15 To: [hidden email] Subject: adding "T2" to variable names Dear list I've been trying for a while now to add a "T2" to the variable names of a dataset. I have a dataset with 120 cases and about 300 variables. Now I'd like to rename v1, v2 .v300 into T2_v1, T2_v2 . T2_v300. Any idea on how to solve that with a neat little script? Philippe ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ |
Alternative, using v14 (though if you have OMS you can use this and drop the DATASET commands and use a temp file) which doesn't read the data in first (more efficient if you have large datasets to open).
DATASET DECLARE VarNames. OMS /SELECT TABLES /IF COMMANDS = ["Sysfile Info"] SUBTYPES = ["Variable Information"] /DESTINATION FORMAT = SAV OUTFILE = VarNames. OMS /SELECT ALL /IF COMMANDS = ["Sysfile Info"] /DESTINATION VIEWER = NO. SYSFILE INFO 'C:\Program Files\SPSS14\employee data.sav'. OMSEND. DATASET ACTIVATE Varnames. STRING newname(A50). COMPUTE newname=CONCAT("T2",SUBSTR(Var1,2)). DO IF $CASENUM = 1. WRITE OUTFILE='c:\temp\rename2.sps' / 'GET FILE="C:\Program Files\SPSS14\employee data.sav" /RENAME 'Var1'='newname' '. ELSE. WRITE OUTFILE='c:\temp\rename2.sps' / ' /RENAME 'Var1'='newname'.'. END IF. Execute. INCLUDE 'C:\temp\rename2.sps'. DATASET NAME renamed_data. DATASET CLOSE Varnames. Rgds, Antro. |
This works:
*[1st some data]. data list free /v1 v2 v3. begin data 1 2 3 end data. define !Macaroni (Cheese = !charend('/')) !do !T !in (!Cheese) rename variables (!T = !concat(T2_, !T)). !doend !enddefine. !Macaroni Cheese = v1 v2 v3 /. *[Just be sure to use the variables dialogue to SHIFT+select & Paste all 300 vars at once]. On 9/15/06, Antro, Mark <[hidden email]> wrote: > > Alternative, using v14 (though if you have OMS you can use this and drop > the DATASET commands and use a temp file) which doesn't read the data in > first (more efficient if you have large datasets to open). > > DATASET DECLARE VarNames. > OMS > /SELECT TABLES > /IF COMMANDS = ["Sysfile Info"] > SUBTYPES = ["Variable Information"] > /DESTINATION FORMAT = SAV > OUTFILE = VarNames. > OMS > /SELECT ALL > /IF COMMANDS = ["Sysfile Info"] > /DESTINATION VIEWER = NO. > > SYSFILE INFO > 'C:\Program Files\SPSS14\employee data.sav'. > > OMSEND. > DATASET ACTIVATE Varnames. > STRING newname(A50). > COMPUTE newname=CONCAT("T2",SUBSTR(Var1,2)). > DO IF $CASENUM = 1. > WRITE OUTFILE='c:\temp\rename2.sps' > / 'GET FILE="C:\Program Files\SPSS14\employee data.sav" /RENAME > 'Var1'='newname' '. > ELSE. > WRITE OUTFILE='c:\temp\rename2.sps' > / ' /RENAME 'Var1'='newname'.'. > END IF. > Execute. > > INCLUDE 'C:\temp\rename2.sps'. > DATASET NAME renamed_data. > DATASET CLOSE Varnames. > > Rgds, > Antro. > |
Dear Friend
Use this procedure with macro for solve your problem. This is a sample for four variables v1 v2 v3 and v4. You can make this with more variables with any names. Very much thanks. /*--------------------------------------------------------------------------------------- DEFINE renamefort2 (ListVariables=!CMDEND) !DO !Variables !IN (!ListVariables) RENAME VARIABLES (!Variables = !CONCAT('T2_',!Variables)). !DOEND. !ENDDEFINE. /*--------------------------------------------------------------------------------------- renamefort2 ListVariables=v1 v2 v3 v4. /*--------------------------------------------------------------------------------------- Carlos Renato Statistician +55 (81)3581.1246 |
Free forum by Nabble | Edit this page |