|
For a variable VAR1, we have 1-200 value labels.
In those only the applicable value labels are only 70 (randomly) means rest 130 (randomly) has no data in this perticular data set. Is there any way to remove those dummy value labels (130) for that variable. Solution may be for one variable or multiple variables also fine. Thanks in advance, Sneha |
|
Please clarify your situation.
How can 1 variable VAR1 have 1 to 200 value labels? If your dictionary is for several datasets, what benefit is there to removing value labels? Except for DISPLAY the value labels will not appear in the output. try the syntax snippet below. data list list/ var1 (f3). begin data 11 28 30 end data. value labels var1 1 'a' 11 'aa' 28 'a word' 30 'something' 55 'why' 99 'why not'. frequencies variables = var1.
Art Kendall
Social Research Consultants |
|
GGRAPH and CTABLES will by default use value labels to determine categories to display, but this option can be turned off. Most (all?) other procedures do not. To get rid of value labels with no data requires a little Python programmability, which I can supply if this is really needed. Please clarify On Mon, Feb 29, 2016 at 7:46 AM, Art Kendall <[hidden email]> wrote: Please clarify your situation. |
|
I see that the CODEBOOK command always displays all the labeled values whether or not you ask for any statistics. On Mon, Feb 29, 2016 at 8:34 AM, Jon Peck <[hidden email]> wrote:
|
|
In reply to this post by Jon Peck
Thanks for the reply..
Our requirement: We are maintaining year wise data for products/brands from 2010-2014. We have combined data set from 10 to 14 with cumilative value labels from 1 to 200. Now we wants to split the data file to maintain year wise data. We able to split the files with combined value labels only.But we want the data file with applicable value labels for each variable. It would be helpful if you can provide a python program to remove the dummy value labels from the variables. |
|
Here is the code to run from the syntax window to do this. Usage instructions are in the code. If you need to limit the variables to process to a specified list, that could be added. Copy it to a syntax window being careful to preserve the indentation. I can't send it as an attachment either to you directly or via the X list. * Encoding: UTF-8. begin program. # delete value labels that have no corresponding value in the data # By default, all variables are processed. Set omitscale=True in the last line # to process only categorical variables. import spss, spssaux, spssdata def reducelabels(omitscale=False): """reduce value labels to only those corresponding to current values If omitscale is True, variables with a scale measurement level are not processed""" if omitscale: vardict = spssaux.VariableDict(variableLevel=["nominal", "ordinal", "unknown"]) else: vardict = spssaux.VariableDict() allvalues = {} # will track value occurrence for each variable thevars = sorted([(v.VariableIndex, v.VariableName) for v in vardict]) thevars = [item[1] for item in thevars] for v in thevars: allvalues[v] = set() # find all values for selected variables curs = spssdata.Spssdata(thevars, names=False, convertUserMissing=False) for case in curs: for i, v in enumerate(thevars): if isinstance(case[i], basestring): allvalues[v].add(case[i].rstrip()) else: allvalues[v].add(case[i]) curs.CClose() # reduce value labels labelsdeleted = 0 for va in thevars: vls = vardict[va].ValueLabelsTyped # get current labels keep = set(vls.keys()).intersection(allvalues[va]) labelsdeleted += len(vls) - len(keep) vardict[va].ValueLabels = dict([(k,v) for (k,v) in vls.items() if k in keep]) print "***Labels deleted: %s" % labelsdeleted reducelabels(omitscale=False) end program. On Mon, Feb 29, 2016 at 10:37 PM, snehachidire <[hidden email]> wrote: Thanks for the reply.. |
| Free forum by Nabble | Edit this page |
