Search code examples
macrosspss

NMISS on all variables


I am trying to count the missings in my dataset, but I have a problem. My first question is named Q2, and the last one is Q55A7. Thus, I cannot use NMISS(Q2 to Q55A7). is there no way to do it by the ID instead of the name? Or how can I get this working?


Solution

  • Actuall NMISS(Q2 to Q55A7) shouls work fine - when you are referring to variables in the data with the to keyword SPSS doesn't look at the structure of the name, it just takes all the variables in the data that are between these two, according to their order in the data.
    The problem you may run into is with the existance of other variables that you don't want included (e.g. an open ended question in between the other questions. Here are a couple of ways to work around that -
    Let's say your variables are ordered as follows: Q2 Q3 Q4 Q4Other Q5 Q6 Q55A7. Using Q2 to Q55A7 will incluede Q4Other which is an open ended text variable which you can't include in the calculation. In this case you can use:

    nmiss(Q3 to Q4, Q5 to Q55A7)
    

    Now if there are many more variables, and many variables you need to skip, the above method becomes as bothersome as stating all the variables' names. Another way to go back to nmiss(Q3 to Q55A7) is by changing the order of the variables so only the numeric variables you want in the analysis are actually placed between these two. One way to do that is:

    add files /file=* /keep Q4Other Q17Other SomeOtherOpenQ all.
    

    Rrunning this will bring all the specified variables to the beginnig of the dataset, leaving only the variables you want in the analysis between Q3 to Q55A7.

    If you still want to inprove on that, you can look up spssinc select variables (see my answer here for example) extention command which enables you to define variable lists according to their attributes, and then you can run the analysis on a list of variables.