I am running some intensive analysis of the 5th wave (2010) of the European Social Survey (ESS). There are 642 variables and 26 countries in this wave (N=50781) but I’m using only the British data (N=2422). I work almost exclusively in SPSS syntax, but find the ESS mnemonic variable names almost unuseable, especially since the question numbers are not included in the variable labels. The names are also limited to 8 characters, so there are some pretty tortuous and meaningless abbreviations. I appreciate that, to enable analysis of trends, they need to keep variable names consistent across waves, but the question numbers are always the same anyway. OK so the GUI doesn’t make mistakes with variable names (or even syntax errors) and syntax users are prone to these. However I work direct from the questionnaire and the variable names are not included in that. Fortunately the SPSS saved file has all variables in questionnaire order. I started with something like this: Name Label ppltrst Most people can be trusted or you can't be too careful pplfair Most people try to take advantage of you, or try to be fair pplhlp Most of the time people helpful or mostly looking out for themselves I’ve manually added the question number to a few variable labels: Name Label ppltrst A8: Most people can be trusted or you can't be too careful pplfair A9: Most people try to take advantage of you, or try to be fair pplhlp A10: Most of the time people helpful or mostly looking out for themselves and manually changed a couple of variable names, or used RENAME VARIABLES to change another dozen or so, but leaving the variable labels as per ESS: Name Label A8 Most people can be trusted or you can't be too careful A9 Most people try to take advantage of you, or try to be fair A10 Most of the time people helpful or mostly looking out for themselves In some cases I have inserted the question number at the beginning of the label: Name Label A8 A8: Numeric Most people can be trusted or you can't be too careful A9 A9: Numeric Most people try to take advantage of you, or try to be fair A10 A10: Most of the time people helpful or mostly looking out for themselves Being a lazy s.o.b. I don’t fancy having to change 662 variable names and insert 662 question numbers by hand, so I’m looking at a mass RENAME VARIABLES command to change all the names in one fell swoop by copying and pasting the names column and matching the names to A! to An, B1 to Bn, . . .H1 to Hn. On the old Vax (in 1992) I could use EDT in column mode to strip out text, but I don’t think I can do this in MS Word. I might have to use Excel as an intermediate step to Word, but then I’ll have to use [CTRL]+ H and replace all the ^P line feeds. SPSS doesn’t fell forests any more so I don’t mind a syntax file with 700 lines of matched pairs of new and old variable names, or fewer lines using DO REPEAT. For example, if I run: rename var (gdsprt to yrspdwka wrywprb to jbprtfp = G1 to G11 G46 to G48). How can I get automatic insertion of either the new (or possibly also the old) variable names as strings into variable labels to yield a file with either: Name Label G1 G1: Have felt cheerful and in good spirits last 2 weeks G2 G2: Have felt calm and relaxed last 2 weeks G3 G3: Have felt active and vigourous last 2 weeks G7 G7: How much time during past week you felt lonely Or possibly: Name Label G1 G1: Have felt cheerful and in good spirits last 2 weeks [gdsprt] G2 G2: Have felt calm and relaxed last 2 weeks [clmrlx] G3 G3: Have felt active and vigourous last 2 weeks [actvgrs] G7 G7: How much time during past week you felt lonely [fltlnla] You can only imagine what the other 638 original names look like! So instead of typing out: disp lab /var gdsprt clmrlx actvgrs fltlnla.
. . I can type: disp lab /var g1 g2 g3 g7. [NB: I always work in lower case]
This looks repetitive, but with Labels settings (not Names and Labels) the output is very clear and uncluttered e.g: freq g7.
Although I’m doing this for my own benefit, I’m sure that some users, especially students, will find the modified file more user-friendly for secondary analysis. Don’t worry, I’m keeping the original safe and I can always get another download from the ESS website. John F Hall (Mr) Email: [hidden email] Website: www.surveyresearch.weebly.com |
John,
I have to admit that you say WAY too much before getting to the problem which I found confusing. Â Let me highlight some of the things you say below and make a suggestion or two.
First, I assume that you already have the variable labels in your data file.  Second, if you use the display command, you get the following output. |disp lab /var gdsprt clmrlx actvgrs fltlnla.  | |
If you copy the above table into Word, do the following:
NOTE: Â Maintain the table structure in Word because you are going to use Word to modify the table into spss syntax. (1) Delete the second column (i.e., "Position")
(2) Copy Column 1 elsewhere in the document (3) Convert the now two column "table into text" with a separator like ":" . that is, a colon separating the text from the two columns.
You now have a text that looks like the following: Variable : Label Gdsprt : Have felt cheerful and in good spirits last 2 weeks Clmrlx : Have felt calm and relaxed last 2 weeks Actvgrs : Have felt active and vigourous last 2 weeks Fltlnla : How much time during past week you felt lonely(4)  Convert the above text into a table but specify "paragraph" separator.  This produces a table that looks like this:
(5)Â Copy the column of variable names you posted somewhere (see (2) above). Â Highlight the table above. Paste the column of variable names into column 1. Â
You should get something like this:
(6) Add a third column to the right. Â So you now have a table that looks like this:
(7) Convert "Table to Text" but using a separator like ' "', that is a space and a double quote (or single quote if you like). Â This will produce text like the following:
Variable "Variable : Label" Gdsprt "Gdsprt : Have felt cheerful and in good spirits last 2 weeks" Clmrlx "Clmrlx : Have felt calm and relaxed last 2 weeks" Actvgrs "Actvgrs : Have felt active and vigourous last 2 weeks" Fltlnla "Fltlnla : How much time during past week you felt lonely"On the left you have the variable name and in the quotes you have the variable label.  Of course you can modify
this to suit one's own tastes and style. I think this addresses what you want but I could be wrong. -Mike Palij New York University
On Thu, Oct 25, 2012 at 7:16 AM, John F Hall <[hidden email]> wrote:
|
Administrator
|
In reply to this post by John F Hall
Hi John. I think I would try something like this:
1. Use OMS to write the table of variable labels (produced via DISPLAY LABELS) to a new dataset. 2. Activate that new dataset, and then use CONCAT to compute a new string variable VarLabs holding the lines for a new VARIABLE LABELS command. VarLabs would have values such as: "G1 'G1: Have felt cheerful and in good spirits last 2 weeks'" "G2 'G2: Have felt calm and relaxed last 2 weeks'" etc 3. In a syntax window, type VARIABLE LABELS on one line, and paste in the values of your newly computed string variable below -- with a command terminator stuck on at the end. VARIABLE LABELS { paste in values of VarLabs here } . HTH.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
In reply to this post by John F Hall
To sequentially rename the variables and
add the sequence number to the label, this little Python code will do the
job. Note that the two lines after "for" must be indented.
begin program. import spss, spssaux vardict = spssaux.VariableDict() for qnum, v in enumerate(vardict): v.VariableLabel = "A" + str(qnum+1) + ":" + v.VariableLabel spss.Submit("rename variable %s = A%s" %(v.VariableName, str(qnum+1))) end program. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: John F Hall <[hidden email]> To: [hidden email], Date: 10/25/2012 04:18 AM Subject: [SPSSX-L] Rename vars and change var labels at same time Sent by: "SPSSX(r) Discussion" <[hidden email]> I am running some intensive analysis of the 5th wave (2010) of the European Social Survey (ESS). There are 642 variables and 26 countries in this wave (N=50781) but I’m using only the British data (N=2422).
I work almost exclusively in SPSS syntax, but find the ESS mnemonic variable names almost unuseable, especially since the question numbers are not included in the variable labels. The names are also limited to 8 characters, so there are some pretty tortuous and meaningless abbreviations.
I appreciate that, to enable analysis of trends, they need to keep variable names consistent across waves, but the question numbers are always the same anyway. OK so the GUI doesn’t make mistakes with variable names (or even syntax errors) and syntax users are prone to these. However I work direct from the questionnaire and the variable names are not included in that. Fortunately the SPSS saved file has all variables in questionnaire order.
I started with something like this:
Name Label ppltrst Most people can be trusted or you can't be too careful pplfair Most people try to take advantage of you, or try to be fair pplhlp Most of the time people helpful or mostly looking out for themselves
I’ve manually added the question number to a few variable labels:
Name Label ppltrst A8: Most people can be trusted or you can't be too careful pplfair A9: Most people try to take advantage of you, or try to be fair pplhlp A10: Most of the time people helpful or mostly looking out for themselves
and manually changed a couple of variable names, or used RENAME VARIABLES to change another dozen or so, but leaving the variable labels as per ESS:
Name Label A8 Most people can be trusted or you can't be too careful A9 Most people try to take advantage of you, or try to be fair A10 Most of the time people helpful or mostly looking out for themselves
In some cases I have inserted the question number at the beginning of the label:
Name Label A8 A8: Numeric Most people can be trusted or you can't be too careful A9 A9: Numeric Most people try to take advantage of you, or try to be fair A10 A10: Most of the time people helpful or mostly looking out for themselves
Being a lazy s.o.b. I don’t fancy having to change 662 variable names and insert 662 question numbers by hand, so I’m looking at a mass RENAME VARIABLES command to change all the names in one fell swoop by copying and pasting the names column and matching the names to A! to An, B1 to Bn, . . .H1 to Hn. On the old Vax (in 1992) I could use EDT in column mode to strip out text, but I don’t think I can do this in MS Word. I might have to use Excel as an intermediate step to Word, but then I’ll have to use [CTRL]+ H and replace all the ^P line feeds. SPSS doesn’t fell forests any more so I don’t mind a syntax file with 700 lines of matched pairs of new and old variable names, or fewer lines using DO REPEAT.
For example, if I run:
rename var (gdsprt to yrspdwka wrywprb to jbprtfp = G1 to G11 G46 to G48).
How can I get automatic insertion of either the new (or possibly also the old) variable names as strings into variable labels to yield a file with either:
Name Label G1 G1: Have felt cheerful and in good spirits last 2 weeks G2 G2: Have felt calm and relaxed last 2 weeks G3 G3: Have felt active and vigourous last 2 weeks G7 G7: How much time during past week you felt lonely
Or possibly:
Name Label G1 G1: Have felt cheerful and in good spirits last 2 weeks [gdsprt] G2 G2: Have felt calm and relaxed last 2 weeks [clmrlx] G3 G3: Have felt active and vigourous last 2 weeks [actvgrs] G7 G7: How much time during past week you felt lonely [fltlnla]
You can only imagine what the other 638 original names look like! So instead of typing out:
disp lab /var gdsprt clmrlx actvgrs fltlnla.
. . I can type: disp lab /var g1 g2 g3 g7. [NB: I always work in lower case]
This looks repetitive, but with Labels settings (not Names and Labels) the output is very clear and uncluttered e.g:
freq g7.
Although I’m doing this for my own benefit, I’m sure that some users, especially students, will find the modified file more user-friendly for secondary analysis. Don’t worry, I’m keeping the original safe and I can always get another download from the ESS website.
John F Hall (Mr)
Email: johnfhall@... Website: www.surveyresearch.weebly.com
|
In reply to this post by John F Hall
Reuben I have to work with the file as distributed by the European Social Survey (ESS) team from: http://www.europeansocialsurvey.org/ The saved file as downloaded for the 5th wave in 2010 follows the variable naming and labelling convention below: Name Label ppltrst Most people can be trusted or you can't be too careful pplfair Most people try to take advantage of you, or try to be fair pplhlp Most of the time people helpful or mostly looking out for themselves Mnemonic variable names like these are an absolute nightmare to work with, especially in syntax: I want to change the names and their associated labels to look like this so that I (and others) can work direct from the questionnaire: (New) (New) Name Label A8 A8: Most people can be trusted or you can't be too careful [ppltrst] A9 A9: Most people try to take advantage of you, or try to be fair [pplfair] A10 A10: Most of the time people helpful or mostly looking out for themselves [pplhlp] . . so the short answer to your question about retaining original variable names in the new labels is (possibly) “Yes”. but it might be just as easy to make the changes as and when I use each (set of) variables. This is the equivalent of writing: rename var (ppltrst pplfair pplhlp = A8 A9 A10). var lab A8 'A8: Most people can be trusted or you can't be too careful [ppltrst] ' /A9 'A9: Most people try to take advantage of you, or try to be fair [pplfair] ' /A10 'A10: Most of the time people helpful or mostly looking out for themselves [pplhlp] '. . . . which I can just as easily do manually in the Data Editor, except that no syntax is generated. I was just looking for an easy way to change all 642 variables in one pass using something like: rename var (<oldvar1> to <oldvarn> = newvar1 to newvarn). . . .where <newvars> are generated as A1 to A10, B1 to B40 ~ ~ ~ G1 to G88 plus the items from sections H, I and J. As a useful tool I might have an Excel file with the original names in one comun and the new names in another so that in the unlikely event of total failure at ESS I can recreate their files with the original variable names. Sorry you lost me half-way through, but the students on my Survey Analysis Workshop (1976 to 1992) had no problems whatsoever understanding why the original variable names needed to be changed: on that course the data were usually from the British Social Attitudes (BSA) survey, but, at my suggestion more than 20 years ago, Natcen started to put the question number at beginning of each variable label. The ESS still follows the original SPSS dictionary convention for the BSA survey by Prof John Curtice and Ann Mair of Strathclyde University in 1983: it has still to catch up with Natcen. If you still don’t follow the thrust of all this, have a look at my tutorial It dates from the days of 80-column Hollerith cards in the 1970s and the consequent need to read data from card images, but the logic stands: these days for positional variable names, read question numbers. This is paramount when often the only documentation available is the questionnaire. The files I construct and the tutorials I write assume relative newbie status to, and fleeting contact with, SPSS, Gradpack only (so no Python or other add-ons) and no specialist background in computing or statistics (or sometimes even basic numeracy). Reports and articles are usually aimed at the intelligent lay reader and applied researcher rather than academic journals or specialisms. (See for instance the list of articles by Mark Abrams and myself on http://surveyresearch.weebly.com/quality-of-life-publications.html ) John Email: [hidden email] Website: www.surveyresearch.weebly.com From: Ruben van den Berg [mailto:[hidden email]] Dear John, I'm pretty sure you can do it in a few lines with Python but honestly, I lost you about halfway your post. Where are the new variable names? Would you like to ADD the original variable names to the variable labels (perhaps separated by a delimiter such as ":" to render it reversible)? Best, Ruben Date: Thu, 25 Oct 2012 13:16:35 +0200 I am running some intensive analysis of the 5th wave (2010) of the European Social Survey (ESS). There are 642 variables and 26 countries in this wave (N=50781) but I’m using only the British data (N=2422). I work almost exclusively in SPSS syntax, but find the ESS mnemonic variable names almost unuseable, especially since the question numbers are not included in the variable labels. The names are also limited to 8 characters, so there are some pretty tortuous and meaningless abbreviations. I appreciate that, to enable analysis of trends, they need to keep variable names consistent across waves, but the question numbers are always the same anyway. OK so the GUI doesn’t make mistakes with variable names (or even syntax errors) and syntax users are prone to these. However I work direct from the questionnaire and the variable names are not included in that. Fortunately the SPSS saved file has all variables in questionnaire order. I started with something like this: Name Label ppltrst Most people can be trusted or you can't be too careful pplfair Most people try to take advantage of you, or try to be fair pplhlp Most of the time people helpful or mostly looking out for themselves I’ve manually added the question number to a few variable labels: Name Label ppltrst A8: Most people can be trusted or you can't be too careful pplfair A9: Most people try to take advantage of you, or try to be fair pplhlp A10: Most of the time people helpful or mostly looking out for themselves and manually changed a couple of variable names, or used RENAME VARIABLES to change another dozen or so, but leaving the variable labels as per ESS: Name Label A8 Most people can be trusted or you can't be too careful A9 Most people try to take advantage of you, or try to be fair A10 Most of the time people helpful or mostly looking out for themselves In some cases I have inserted the question number at the beginning of the label: Name Label A8 A8: Numeric Most people can be trusted or you can't be too careful A9 A9: Numeric Most people try to take advantage of you, or try to be fair A10 A10: Most of the time people helpful or mostly looking out for themselves Being a lazy s.o.b. I don’t fancy having to change 662 variable names and insert 662 question numbers by hand, so I’m looking at a mass RENAME VARIABLES command to change all the names in one fell swoop by copying and pasting the names column and matching the names to A! to An, B1 to Bn, . . .H1 to Hn. On the old Vax (in 1992) I could use EDT in column mode to strip out text, but I don’t think I can do this in MS Word. I might have to use Excel as an intermediate step to Word, but then I’ll have to use [CTRL]+ H and replace all the ^P line feeds. SPSS doesn’t fell forests any more so I don’t mind a syntax file with 700 lines of matched pairs of new and old variable names, or fewer lines using DO REPEAT. For example, if I run: rename var (gdsprt to yrspdwka wrywprb to jbprtfp = G1 to G11 G46 to G48). How can I get automatic insertion of either the new (or possibly also the old) variable names as strings into variable labels to yield a file with either: Name Label G1 G1: Have felt cheerful and in good spirits last 2 weeks G2 G2: Have felt calm and relaxed last 2 weeks G3 G3: Have felt active and vigourous last 2 weeks G7 G7: How much time during past week you felt lonely Or possibly: Name Label G1 G1: Have felt cheerful and in good spirits last 2 weeks [gdsprt] G2 G2: Have felt calm and relaxed last 2 weeks [clmrlx] G3 G3: Have felt active and vigourous last 2 weeks [actvgrs] G7 G7: How much time during past week you felt lonely [fltlnla] You can only imagine what the other 638 original names look like! So instead of typing out: disp lab /var gdsprt clmrlx actvgrs fltlnla.
. . I can type: disp lab /var g1 g2 g3 g7. [NB: I always work in lower case]
This looks repetitive, but with Labels settings (not Names and Labels) the output is very clear and uncluttered e.g: freq g7.
Although I’m doing this for my own benefit, I’m sure that some users, especially students, will find the modified file more user-friendly for secondary analysis. Don’t worry, I’m keeping the original safe and I can always get another download from the ESS website. John F Hall (Mr) Email: [hidden email] Website: www.surveyresearch.weebly.com |
Administrator
|
<SNIP egregious blah blah blah and self promotional blather...TMI John, TMTMI!!!!>
"The files I construct and the tutorials I write assume relative newbie status to, and fleeting contact with, SPSS, Gradpack only (so no Python or other add-ons" AFAIK Gradpack is a fully functional version of SPSS...you only need to DL the apt Python etc... It appears that it is nearly impossible to teach old dogs new tricks. A career of doing crosstabs and freqs on surveys?
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
David At almost 72, being happily retired and having worked closely over many years with some of the biggest names in social (survey) research, I have neither need of, nor desire for, self-promotion. However there are untold hundreds of students and researchers out there who need the benefit of my experience, especially when, mindful of other researchers who may also need to use the data, they are producing SPSS saved files and documentation for their own surveys. As you well know, this old dog can do (and has done) a lot more than crosstabs and frequencies. I would point out that, for beginners, these provide a useful stepping stone to more advance methods of analysis. A good researcher can tell a hell of a lot from looking at frequency distributions (aka hole-counts) and, as my old boss the late Dr Mark Abrams used to say, "If it's worth saying, you can say it in percentages." But he would have appreciated the charts available these days. Meanwhile I'm still waiting for a bit of syntax before that to pick up existing variable names (copy them as strings?) and insert them as per my previous entries) then. 1: [command to pick up existing varnames and copy them in (in square brackets) to the end of the variable labels 2: RENAME VAR to change the var names 3: [command to pick up the new names and insert them at the beginning of the variable labels, but adding a colon and at least one space Should be pretty straightforward for someone with undoubted experience and skill. Other listers have made some interesting (if occasionally laborious) suggestions: I'm still waiting for yours. Yours in permanent admiration (and occasional exasperation) John F Hall (Mr) Email: [hidden email] Website: www.surveyresearch.weebly.com -----Original Message----- <SNIP egregious blah blah blah and self promotional blather...TMI John, TMTMI!!!!> "The files I construct and the tutorials I write assume relative newbie status to, and fleeting contact with, SPSS, Gradpack only (so no Python or other add-ons" AFAIK Gradpack is a fully functional version of SPSS...you only need to DL the apt Python etc... It appears that it is nearly impossible to teach old dogs new tricks. A career of doing crosstabs and freqs on surveys? ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Rename-vars-and-change-var-labels-at-same-time-tp5715863p5715879.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by John F Hall
John,
This is the sort of problem I solve with Excel (or as I call it, the poor man's macro). I go into variable view, copy the name and label columns into Excel, and set up new columns with the appropriate names. Then I'd use the concatenate function to combine the name and old label to make the new label. Paste the values into the SPSS commands (RENAME and VALUE LABELS). The hard manual part is setting up variable names, but since most of the names will be in a logical order, you can have Excel do much of that work (eg., use auto-fill and increment to fill in cells with A1 to An). Barry On Thu, 25 Oct 2012 13:16:35 +0200, John F Hall <[hidden email]> wrote: >How can I get automatic insertion of either the new (or possibly also the >old) variable names as strings into variable labels to yield a file with >either: > >Name Label >G1 G1: Have felt cheerful and in good spirits last 2 weeks >G2 G2: Have felt calm and relaxed last 2 weeks >G3 G3: Have felt active and vigourous last 2 weeks >G7 G7: How much time during past week you felt lonely > >Or possibly: > >Name Label >G1 G1: Have felt cheerful and in good spirits last 2 weeks >[gdsprt] >G2 G2: Have felt calm and relaxed last 2 weeks [clmrlx] >G3 G3: Have felt active and vigourous last 2 weeks [actvgrs] >G7 G7: How much time during past week you felt lonely [fltlnla] > >You can only imagine what the other 638 original names look like! So >instead of typing out: ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Dear Barry,
You are aware that these sorts of jobs can usually be done without any manual work with just a few lines of Python code, right? The main things you'll have to do, is download + run a single installation file, ask this list to write these few lines for you and copy-paste-run them. Perhaps I'm missing something but I really don't see why anybody would still prefer manual work (labor intensive, error prone, hard to document, not repeatable) if there is such an easy alternative. Best, Ruben > Date: Fri, 26 Oct 2012 11:05:08 -0400 > From: [hidden email] > Subject: Re: Rename vars and change var labels at same time > To: [hidden email] > > John, > > This is the sort of problem I solve with Excel (or as I call it, the poor > man's macro). I go into variable view, copy the name and label columns into > Excel, and set up new columns with the appropriate names. Then I'd use the > concatenate function to combine the name and old label to make the new > label. Paste the values into the SPSS commands (RENAME and VALUE LABELS). > The hard manual part is setting up variable names, but since most of the > names will be in a logical order, you can have Excel do much of that work > (eg., use auto-fill and increment to fill in cells with A1 to An). > > Barry > > On Thu, 25 Oct 2012 13:16:35 +0200, John F Hall <[hidden email]> wrote: > > >How can I get automatic insertion of either the new (or possibly also the > >old) variable names as strings into variable labels to yield a file with > >either: > > > >Name Label > >G1 G1: Have felt cheerful and in good spirits last 2 weeks > >G2 G2: Have felt calm and relaxed last 2 weeks > >G3 G3: Have felt active and vigourous last 2 weeks > >G7 G7: How much time during past week you felt lonely > > > >Or possibly: > > > >Name Label > >G1 G1: Have felt cheerful and in good spirits last 2 weeks > >[gdsprt] > >G2 G2: Have felt calm and relaxed last 2 weeks [clmrlx] > >G3 G3: Have felt active and vigourous last 2 weeks [actvgrs] > >G7 G7: How much time during past week you felt lonely [fltlnla] > > > >You can only imagine what the other 638 original names look like! So > >instead of typing out: > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD |
Administrator
|
In reply to this post by John F Hall
"Meanwhile I'm still waiting for a bit of syntax before that to pick up existing variable names (copy them as strings?) and insert them as per my previous entries) then."
SPSS Syntax does not have access to the data dictionary (neither does MACRO). DO REPEAT will render an epic fail for about 100 reasons. Hence you are going to require either Python Scripting (see Jon's solution) or Basic Scripting. I posted an Basic soution similar to what you wish some time ago. Feel free to amend it to your requirements. http://spssx-discussion.1045642.n5.nabble.com/Add-a-suffix-to-all-variable-names-td5714298.html#a5714310 NOTE: varnames=objSpssApp.Documents.GetDataDoc(0).GetVariables (False) will be changed to varnames=objSpssApp.Documents.GetDataDoc(0).GetVariables (True) Parse the items in the array then build your 2 commands. ----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Ruben Geert van den Berg
While I would tend to agree with Ruben, he does miss the obvious:
that one might use a machine that does not have Python installed on it (for whatever reason; sometimes the powers that be do not agree that something like Python should be on a machine). However, given the procedure I outlined using Word, I would like to know why such a procedure is "hard to document" and "not repeatable"? Aren't the steps clearly defined and easy to follow? The amount of labor involved in the procedure was actually fairly trivial and one would have to be excessive error prone to make a error with it (I would agree that some people can't do the simplest things without getting them wrong). So, if you were on a PC or some other system that didn't have python, how would one accomplish the task? The answer "Go find a PC with a properly installed python package" is not an acceptable answer. -Mike Palij New York University [hidden email] On Fri, Oct 26, 2012 at 11:41 AM, Ruben van den Berg <[hidden email]> wrote: > Dear Barry, > > You are aware that these sorts of jobs can usually be done without any > manual work with just a few lines of Python code, right? The main things > you'll have to do, is download + run a single installation file, ask this > list to write these few lines for you and copy-paste-run them. > > Perhaps I'm missing something but I really don't see why anybody would still > prefer manual work (labor intensive, error prone, hard to document, not > repeatable) if there is such an easy alternative. > > Best, > > Ruben > >> Date: Fri, 26 Oct 2012 11:05:08 -0400 >> From: [hidden email] >> Subject: Re: Rename vars and change var labels at same time >> To: [hidden email] >> >> John, >> >> This is the sort of problem I solve with Excel (or as I call it, the poor >> man's macro). I go into variable view, copy the name and label columns >> into >> Excel, and set up new columns with the appropriate names. Then I'd use the >> concatenate function to combine the name and old label to make the new >> label. Paste the values into the SPSS commands (RENAME and VALUE LABELS). >> The hard manual part is setting up variable names, but since most of the >> names will be in a logical order, you can have Excel do much of that work >> (eg., use auto-fill and increment to fill in cells with A1 to An). >> >> Barry >> >> On Thu, 25 Oct 2012 13:16:35 +0200, John F Hall <[hidden email]> >> wrote: >> >> >How can I get automatic insertion of either the new (or possibly also the >> >old) variable names as strings into variable labels to yield a file with >> >either: >> > >> >Name Label >> >G1 G1: Have felt cheerful and in good spirits last 2 weeks >> >G2 G2: Have felt calm and relaxed last 2 weeks >> >G3 G3: Have felt active and vigourous last 2 weeks >> >G7 G7: How much time during past week you felt lonely >> > >> >Or possibly: >> > >> >Name Label >> >G1 G1: Have felt cheerful and in good spirits last 2 weeks >> >[gdsprt] >> >G2 G2: Have felt calm and relaxed last 2 weeks [clmrlx] >> >G3 G3: Have felt active and vigourous last 2 weeks [actvgrs] >> >G7 G7: How much time during past week you felt lonely [fltlnla] >> > >> >You can only imagine what the other 638 original names look like! So >> >instead of typing out: >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to >> [hidden email] (not to SPSSX-L), with no body text except the >> command. To leave the list, send the command >> SIGNOFF SPSSX-L >> For a list of commands to manage subscriptions, send the command >> INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
"So, if you were on a PC or some other system that didn't have
python, how would one accomplish the task?" SPSS has had some form of Basic scripting for about 15 years!!! See my previous post. There is sufficient meat there for John to study and apply to arriving at a complete solution. Definitely enough rope!
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Administrator
|
Another important factor, I think, is whether one is looking at a one-time job versus something that will have to be done repeatedly. In John's case, I suspect it is a one-time job. When it is clearly a one-time job, it may be difficult to justify the extra time & effort required to come create the more elegant solution that entails programming--especially if one is not a particularly good programmer.
Donning flame-resistant suit and hiding under my desk... ;-)
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Administrator
|
Well this isn't so complex ;-) I leave it to John to be sure all original variables have some initial label. Otherwise there may be an error. ----- Option Explicit Sub Main Dim i As Integer Dim varnames() As String varnames=objSpssApp.Documents.GetDataDoc(0).GetVariables (True) For i=0 To UBound(varnames)-1 objSpssApp.ExecuteCommands "RENAME VARIABLES " & Left( varnames(i),InStr(varnames(i),vbTab)-1) & "=" & "V" & i+1 & "." & vbCrLf & _ "VARIABLE LABELS " & "V" & i+1 & " '" & "V" & i+1 & _ ": " & Right(Left( varnames(i),InStr(varnames(i),vbTab)-1),InStr(varnames(i),vbTab)+1) & _ " [" & Left( varnames(i),InStr(varnames(i),vbTab)-1) & "]" & "'" & "." ,False Next End Sub
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Bruce Weaver
That is an important point: it's certainly
harder to justify programming a solution to a simple one-time problem,
although you should consider the boredom factor in deciding. But
even with a one-time problem, you need to ask how you know that the result
is correct. It is typically easier to verify a small, well-written
program than to rule out error in a manual process. In John's case
that would require looking at hundreds of outcomes vs checking something
like the four-line program I posted.
Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: Bruce Weaver <[hidden email]> To: [hidden email], Date: 10/26/2012 11:47 AM Subject: Re: [SPSSX-L] Rename vars and change var labels at same time Sent by: "SPSSX(r) Discussion" <[hidden email]> Another important factor, /I think/, is whether one is looking at a one-time job versus something that will have to be done repeatedly. In John's case, I suspect it is a one-time job. When it is clearly a one-time job, it may be difficult to justify the extra time & effort required to come create the more elegant solution that entails programming--/especially/ if one is not a particularly good programmer. Donning flame-resistant suit and hiding under my desk... ;-) David Marso wrote > "So, if you were on a PC or some other system that didn't have > python, how would one accomplish the task?" > > SPSS has had some form of Basic scripting for about 15 years!!! > See my previous post. There is sufficient meat there for John to study > and apply to arriving at a complete solution. Definitely enough rope! ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Rename-vars-and-change-var-labels-at-same-time-tp5715863p5715893.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Free forum by Nabble | Edit this page |