Is there any way in syntax(or otherwise) to select (and count) the number of values in a variable?
I understand that VALUE LABELS is to assign them, but how would I select already existing values/Value labels? The reason being is: I'm trying to write a script in SAX/WinWrap basic that allows me to auto-code the value labels of variables in three ways: 1 - Via input box: User is prompted to enter variable and then a loop selects the next available value and prompts the user to enter a value label for each value that hasn't got a label already. 2 - By directly copying: User is prompted to enter variable and then a loop reads the value, if it is a string the script puts a upper case letter at the start and replaces any ^s with 's (a common error when exporting from cati or excel) and then displays a message box saying the coding is complete. 3 - Shift the value labels by a specified amount, user is prompted to enter the number (positive or negative) that they want the labels to move (very usefull when recoding large numbers of values) i.e. if you have 245 values and you remove number 36 and 37 from the list, you'd have to redo the value labels of every value after 35 so that they were 2 places closer if you wanted consecutive values. Here's part of my proto/pseudo code: Sub Main '##################### 'Begin Description 'Script to apply value labels via a text box input to each number present in a value list. 'End Description '##################### On Error GoTo Bye 'Variable Declaration: Dim i As Integer, intCount As Integer, current As Integer Dim strValName As String, strVar As String, strCom As String, strVariable As String Dim varLabels() As Variant 'This should really be an array of all the value labels in the selected record Dim objSpssApp 'Original Idea was to use two loops 'The first loop would fill an array with the value lables and use the index as the value and 'The second loop would check to see which values already had labels and then 'Would ask the user for a value label to apply to each value that didn't. 'this section is just pseudo For i = 0 To UBound(varLabels) current = GetObject(strVariable.valuelist(i)) 'would use this to get the value Set varLabels(i) = current Next iCounter 'this is the end of just pseudo 'Loop for each number in the Value list. strValName = InputBox("Please specify the variable you wish to name the values of.") 'Loop for each number in the Value list. For i = 0 To varLabels-1 If IsEmpty (varLabels(i)) Then 'Find value and ask for the current value label strVar = InputBox("Please insert Label for value "& varLabels(i) &" :","Insert Value Label") 'Apply the response to the required number strCom = "ADD VALUE LABELS " & strVar & Chr$(39) & intCount & Chr$(39) & Chr$(39) & strValName & Chr$(39) &" ." 'Then the piece of code to execute the Syntax objSpssApp.ExecuteCommands(strCom, False) End If 'intCount = intCount + 1 'increase the count so that it shows the correct number 'it's out of the loop so that even filled value labels are counted Next iCounter End Sub "Lo there do I see my father. Lo there do I see my mother and my sisters and my brothers. Lo there do I see the line of my people, back to the beginning. Lo, they do call to me, they bid me take my place among them, in the Halls of Valhalla, where the brave may live...forever." |
There are many ways to do this. The
simplest is to run AGGREGATE using the variable as a break variable and
creating a new dataset from the output and then examine its size.
Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: Tom1234 <[hidden email]> To: [hidden email] Date: 06/29/2012 08:58 AM Subject: [SPSSX-L] Spss Syntax select all values in a variable? Sent by: "SPSSX(r) Discussion" <[hidden email]> Is there any way in syntax(or otherwise) to select (and count) the number of values in a variable? I understand that VALUE LABELS is to assign them, but how would I select already existing values/Value labels? The reason being is: I'm trying to write a script in SAX/WinWrap basic that allows me to auto-code the value labels of variables in three ways: 1 - Via input box: User is prompted to enter variable and then a loop selects the next available value and prompts the user to enter a value label for each value that hasn't got a label already. 2 - By directly copying: User is prompted to enter variable and then a loop reads the value, if it is a string the script puts a upper case letter at the start and replaces any ^s with 's (a common error when exporting from cati or excel) and then displays a message box saying the coding is complete. 3 - Shift the value labels by a specified amount, user is prompted to enter the number (positive or negative) that they want the labels to move (very usefull when recoding large numbers of values) i.e. if you have 245 values and you remove number 36 and 37 from the list, you'd have to redo the value labels of every value after 35 so that they were 2 places closer if you wanted consecutive values. Here's part of my proto/pseudo code: ----- "Lo there do I see my father. Lo there do I see my mother and my sisters and my brothers. Lo there do I see the line of my people, back to the beginning. Lo, they do call to me, they bid me take my place among them, in the Halls of Valhalla, where the brave may live...forever." -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Spss-Syntax-select-all-values-in-a-variable-tp5713897.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 Tom1234
Alternately, you could use frequencies for the mean and suppress "display frequency tables". For a string field, you will just get the N and count of missing values, while for a numeric you will get the mean but that only occupies one line of the report.
Robert |
Administrator
|
In reply to this post by Tom1234
As Jon said AGGREGATE...
HOWEVER!!! Violating the generally acceptable social convention of "If you can't say anything good don't say anything at all". I am NOT sure what 'problem' such a tool is intended/likely to solve or it's 'real' world applicability. Is there ANY good/necessary reason that values must be consecutive? How is it that the hypothetical 36,37 should be removed from the list of 245? Seems to violate basic principles of data integrity, ability to track from data origins to final deliverable(s). ---- What happens when/if you *EVER* need to merge multiple files which have *NOT* been processed IDENTICALLY by this 'tool'. What happens if/when multiple users hammer on the same file at the same time? What do you tell your client when many of the numbers they thought they had DON'T agree? Short of going BACK to the original source files and tracking down many tiny annoying discrepancies such reconciliation is likely to be hopeless/futile. Usually data is best left alone/as is/unmolested and/or 'corrected' prior to importation into SPSS. Basically in a nutshell, Such a tool permitted to run wild in any group setting or on data of any sort of complexity (relational tables, multiple data waves) without a precise audit trail and backup techniques promises to create MANY more problems than it is likely to solve. Sorry for the overall negative tone of this missive but this is one of those potential '... where angels fear to tread' situations and you may not have thought through the possible terrible implications. I have a RULE: If I can't recreate a deliverable from start to finish from raw data sources with syntax I have failed to create a reproducible/verifiable piece of work and have dropped the ball. I think I will now STFU and return to our previously scheduled programming.
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?" |
Amen!
And unless you can do that you cannot pass a quality assurance review. Long time list members know that one of my soapboxes is that QA review should be built into the very first intros to SPSS. (In accounting "referencing" is standard practice. That is accounting's terminology for QA review.) Also without a full audit trail you cannot go back and do it right. Art Kendall Social Research ConsultantsOn 6/29/2012 1:42 PM, David Marso wrote: I have a RULE: If I can't recreate a deliverable from start to finish from raw data sources with syntax I have failed to create a reproducible/verifiable piece of work and have dropped the ball. ===================== 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
Art Kendall
Social Research Consultants |
In reply to this post by Tom1234
If I understand
correctly #3 can be done something like this, assuming that a
value exists with the desired label.
note that variables are not written over. data list list/x (f2). begin data 1 2 3 4 5 6 7 8 9 10 11 end data. numeric y(f2). value labels x y 1 'abc' 2 'ABC' 3 'Abc' 4 'def' 5 'DEF' 6 'DeF' 7 'dEF' 8 'GHI' 9 'ghi' 10 'Ghi' 11 'ghI'. *recode to the value for all caps. recode x (1 thru 3=2)(4 thru 7=5)(8 thru 11=8) into y. execute. autorecode variables=y /into z. frequencies variables = x y z. Art Kendall Social Research ConsultantsOn 6/29/2012 10:52 AM, Tom1234 wrote: Is there any way in syntax(or otherwise) to select (and count) the number of values in a variable? I understand that VALUE LABELS is to assign them, but how would I select already existing values/Value labels? The reason being is: I'm trying to write a script in SAX/WinWrap basic that allows me to auto-code the value labels of variables in three ways: 1 - Via input box: User is prompted to enter variable and then a loop selects the next available value and prompts the user to enter a value label for each value that hasn't got a label already. 2 - By directly copying: User is prompted to enter variable and then a loop reads the value, if it is a string the script puts a upper case letter at the start and replaces any ^s with 's (a common error when exporting from cati or excel) and then displays a message box saying the coding is complete. 3 - Shift the value labels by a specified amount, user is prompted to enter the number (positive or negative) that they want the labels to move (very usefull when recoding large numbers of values) i.e. if you have 245 values and you remove number 36 and 37 from the list, you'd have to redo the value labels of every value after 35 so that they were 2 places closer if you wanted consecutive values. Here's part of my proto/pseudo code: ----- "Lo there do I see my father. Lo there do I see my mother and my sisters and my brothers. Lo there do I see the line of my people, back to the beginning. Lo, they do call to me, they bid me take my place among them, in the Halls of Valhalla, where the brave may live...forever." -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Spss-Syntax-select-all-values-in-a-variable-tp5713897.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 ===================== 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
Art Kendall
Social Research Consultants |
Administrator
|
In reply to this post by Art Kendall
Brings back one terrible memory from the late 90's (when I was a Sr Consultant at SPSS in Chicago).
Urgent call from back east to Chicago from HUGE marketing research client (MRC) who will remain nameless suggesting possible unspecified (bugs) terrible showstopping problems with SPSS. Flew out the same night got picked up by MRC limo and crashed in a hotel. Arrived 8:00 AM next day ready to rock and roll... Well, their HUGE client was unable to reconcile their reports with MRC's reports... I sat down with their 'analyst' and was appalled to witness her process. She was MANUALLY copying/pasting HUGE blocks of crap from Excel into her master SPSS data file and repeatedly saving over the same copy. WOW!!! WTF am I supposed to do for these people? Well, I tried to describe some fundamentals such as the UPDATE command but all I got were those scary deer in the headlights zombie stare... *BRAINS* I want BRAINS!!! Later that day I had to go with them to an URGENT client meeting where the goal was to explain the numerous glaring discrepancies in a 500 page report. Being the diplomatic, restrained person I am I tried to say as little as possible during that uncomfortable session faintly murmuring something about 'I only saw this for the first time this AM and am attempting to develop some theories about the problem but that will take some time,.... hence I can provide no conclusive suggestions or certifiable remedy at present blah blah blah...snooze (GET ME OUT OF HERE!!!). Flew home that night with a giant headache. Next day MRC's 'analyst's' manager called something like 6 times wanting an explanation of what the problem had been and if we had determined any workaround. WOW!!! Response(s): There is NO problem with the software, there is a problem with your analyst. Is there anything that can be done? 1. Sure, fly me out again and I'll train your analyst how to properly manage data and hopefully wean her of MANY terrible habits and potentially catastrophic practices. 2. Fire the doofus and hire a reasonably competent person to do the job. 3. Prepare to lose more clients if this is your process. They went with option 1.
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 Art Kendall
Hi, May I ask which QA Review template, if any, you use? I find the checklists from the book Code Complete generally VERY useful, though much of it does not apply to SPSS (e.g., no object orientation in SPSS): http://www.matthewjmiller.net/files/cc2e_checklists.pdf Thanks! Regards, Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
This post was updated on .
In reply to this post by Tom1234
A short answer to the angry veterans above haha
1: This is merely to save time manually changing variable names, if there are entries such as 'chippy' but an existing job value has 'Carpenter/joiner' then there is simply no need to have two duplicate variables for analysis, the old variables would not be destroyed simply shown in a more useful way, if an american said 'automobile' and there was a 'Car' category equally you could merge the two. 2: This may have no real world use at all, I just wanted to test the capabilities of the spss built in scripting language and prod the knowledge of those who've used it for ages and wear stripey shirts, big round glasses and have crazy hair ;) 3: I like consecutive numbers, else it looks untidy. EDIT: for those of you from accross the atlantic, a 'chippy' is a slag word for a carpenter or woodworker. EDIT2: The original intended function (before being made into pseuedo code) was to take the value and if it was a string, convert it to a value label and change the first letter to a capital. "Lo there do I see my father. Lo there do I see my mother and my sisters and my brothers. Lo there do I see the line of my people, back to the beginning. Lo, they do call to me, they bid me take my place among them, in the Halls of Valhalla, where the brave may live...forever." |
In reply to this post by Albert-Jan Roskam
I was using "QA review"
in a very general sense. "QA" was capitalized only as an
abbreviation and not because it was a proper name. In quality
management/control one looks at what the process is to see if it
is working as intended and if it can be improved.
I would like to decrease the prevalence of the "lone ranger" model of research and analysis. Review/support by others is part of a team model. I advocate a more realistic portrayal of analysis in introductory classes/workshops by using a team learning syntax based approach. My rationale is based on: ** The purpose of analysis is to support points in an expository, explanatory, or sometimes forensic/adversarial communication. ** In my mind any analysis is an iterative process. ** Getting feedback from others improves an analysis. ** Seeing how other accomplish the same task reinforces cognitive flexibility. ** Syntax is a means of communication. The syntax goes through a series of drafts (polishes, improvements). The GUI is a great way to to get a first draft of syntax. Inevitably a writer will be interrupted during the writing. Syntax allows one to communicate to oneself what (s)he was attempting to do before the interruption. In accounting and in program evaluation there is a process called "referencing" or "peer-review" whereby another person goes through the data and syntax to see if it does what it is supposed to do. Does the approach used support the conclusions stated? Quite often a reviewer asks for clarifications. This can lead to revisions to the syntax. (This is parallel to the way that I ask authors of submitted journal articles "Please tell me more about what you are trying to say here".) Syntax is fundamentally a way to communicate to the computer what you want the computer to do. Syntax communicates to potential helpers what the problem is. Syntax communicates to a person who is seeking help what is being suggested. Syntax communicates to reviewers, supervisors, instructors, people one is instructing, the experts for the other side in a trial, etc. Syntax communicates to other researchers wast was done to reach the conclusions. Getting feedback/review from others results in a more effective and efficient analysis and therefore better support for the statements that result from the analysis. To get an intuitive handle on some of this look at the archives of this list. I find that: Members of the list help the OP get to a clearer statement of what is intended. Different members of the list suggest different approaches. Even expert members such as David go through a refining of their suggestions and post new approaches. Art Kendall Social Research ConsultantsOn 7/1/2012 8:14 AM, Albert-Jan Roskam wrote:
===================== 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
Art Kendall
Social Research Consultants |
In reply to this post by Tom1234
Not only do consecutive
number look more tidy, some procedures (MANOVA) require
consecutive numbers.
Did you look at the approach I suggested. Wouldn't using syntax to Autorecode Recode after eyeballing. Autorecode avoid or at least minimize going outside syntax to scripting, macros, or python? P.S. I very heavily use syntax, have occasionally used macros or python, and have never used scripting. Art Kendall Social Research ConsultantsOn 7/2/2012 7:04 AM, Tom1234 wrote: A short answer to the angry veterans above haha 1: This is merely to save time manually changing variable names, if there are entries such as 'chippy' but an existing job value has 'Carpenter/joiner' then there is simply no need to have two duplicate variables for analysis, the old variables would not be destroyed simply shown in a more useful way, if an american said 'automobile' and there was a 'Car' category equally you could merge the two. 2: This may have no real world use at all, I just wanted to test the capabilities of the spss built in scripting language and prod the knowledge of those who've used it for ages and wear stripey shirts, big round glasses and have crazy hair ;) 3: I like consecutive numbers, else it looks untidy. ----- "Lo there do I see my father. Lo there do I see my mother and my sisters and my brothers. Lo there do I see the line of my people, back to the beginning. Lo, they do call to me, they bid me take my place among them, in the Halls of Valhalla, where the brave may live...forever." -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Spss-Syntax-select-all-values-in-a-variable-tp5713897p5713940.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 ===================== 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
Art Kendall
Social Research Consultants |
@ art
I've looked at your syntax proposal and you're pretty much bang on, *throws script in recycle bin* Thanks very much :) "Lo there do I see my father. Lo there do I see my mother and my sisters and my brothers. Lo there do I see the line of my people, back to the beginning. Lo, they do call to me, they bid me take my place among them, in the Halls of Valhalla, where the brave may live...forever." |
See even a decade after
retirement some of us can still cut the mustard.
Art Kendall Social Research ConsultantsOn 7/2/2012 12:06 PM, Tom1234 wrote: @ art I've looked at your syntax proposal and you're pretty much bang on, *throws script in recycle bin* Thanks very much :) ----- "Lo there do I see my father. Lo there do I see my mother and my sisters and my brothers. Lo there do I see the line of my people, back to the beginning. Lo, they do call to me, they bid me take my place among them, in the Halls of Valhalla, where the brave may live...forever." -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Spss-Syntax-select-all-values-in-a-variable-tp5713897p5713953.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 ===================== 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
Art Kendall
Social Research Consultants |
Administrator
|
In addition, it takes experience to discern when it makes sense to forge ahead versus when to run like hell (or find a different box to think outside of;-)
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?" |
Free forum by Nabble | Edit this page |