Delete variables based on the number of observations in SPSS





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I have a SPSS file that contains about 1000 variables and I have to delete the ones having 0 valid values. I can think of a loop with an if statement but I can't find how to write it.










share|improve this question































    2















    I have a SPSS file that contains about 1000 variables and I have to delete the ones having 0 valid values. I can think of a loop with an if statement but I can't find how to write it.










    share|improve this question



























      2












      2








      2








      I have a SPSS file that contains about 1000 variables and I have to delete the ones having 0 valid values. I can think of a loop with an if statement but I can't find how to write it.










      share|improve this question
















      I have a SPSS file that contains about 1000 variables and I have to delete the ones having 0 valid values. I can think of a loop with an if statement but I can't find how to write it.







      spss






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 2:22









      Cœur

      19.2k9116155




      19.2k9116155










      asked Feb 11 '16 at 19:49









      RenéRené

      113




      113
























          2 Answers
          2






          active

          oldest

          votes


















          3














          The simplest way would be to use the spssaux2.FindEmptyVars Python function like this.



          begin program.

          import spssaux2



          spssaux2.FindEmptyVars(delete=True)

          end program.



          If you don't already have the spssaux2 module installed, you would need to get it from the SPSS Community website or the IBM Predictive Analytics site and save it in the pythonlibsite-packages directory under your Statistics installation.



          Otherwise, the VALIDATEDATA command, if you have it, will identify the variables violating such rules as maximum percentage of missing values, but you would have to turn that output into a DELETE VARIABLES command. You could also look for variables with zero missing values using, say, DESCRIPTIVES and select out the ones with N=0.






          share|improve this answer































            1














            If you've never worked with python in SPSS, here's a way to get the job done without it (not as elegant, but should do the job):



            This will count the valid cases in each variable, and select only those that have 0 valid cases. Then you'll manually copy the names of these variables into a syntax command that will delete them.



            DATASET NAME Orig.
            DATASET DECLARE VARLIST.
            AGGREGATE /OUTFILE='VARLIST'/BREAK=
            /**list_all_the_variable_names_here = NU(*FirstVarName to *LastVarName).
            DATASET ACTIVATE VARLIST.
            VARSTOCASES /MAKE NumValid FROM *FirstVarName to *LastVarName/INDEX=VarName(NumValid).
            SELECT IF NumValid=0.
            EXECUTE.


            Pause here to copy the remaining names in the list and complete the syntax, then continue:



            DATASET ACTIVATE Orig.
            DELETE VARIABLES *paste_here_all_the_remaining_variable_names_from_varlist .


            Notes:
            * I put stars where you have to replace my text with your variable names.
            ** If the variables are neatly named like Q1, Q2, Q3 .... Q1000, you can use the "FirstVarName to LastVarName" form (Q1 to Q1000) instead of listing all the variable names.



            BTW it is of course possible to do this completely automatically without manually copying those names (using only syntax, no Python), but the added complexity is not worth bothering with for a single use...






            share|improve this answer


























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35348734%2fdelete-variables-based-on-the-number-of-observations-in-spss%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              The simplest way would be to use the spssaux2.FindEmptyVars Python function like this.



              begin program.

              import spssaux2



              spssaux2.FindEmptyVars(delete=True)

              end program.



              If you don't already have the spssaux2 module installed, you would need to get it from the SPSS Community website or the IBM Predictive Analytics site and save it in the pythonlibsite-packages directory under your Statistics installation.



              Otherwise, the VALIDATEDATA command, if you have it, will identify the variables violating such rules as maximum percentage of missing values, but you would have to turn that output into a DELETE VARIABLES command. You could also look for variables with zero missing values using, say, DESCRIPTIVES and select out the ones with N=0.






              share|improve this answer




























                3














                The simplest way would be to use the spssaux2.FindEmptyVars Python function like this.



                begin program.

                import spssaux2



                spssaux2.FindEmptyVars(delete=True)

                end program.



                If you don't already have the spssaux2 module installed, you would need to get it from the SPSS Community website or the IBM Predictive Analytics site and save it in the pythonlibsite-packages directory under your Statistics installation.



                Otherwise, the VALIDATEDATA command, if you have it, will identify the variables violating such rules as maximum percentage of missing values, but you would have to turn that output into a DELETE VARIABLES command. You could also look for variables with zero missing values using, say, DESCRIPTIVES and select out the ones with N=0.






                share|improve this answer


























                  3












                  3








                  3







                  The simplest way would be to use the spssaux2.FindEmptyVars Python function like this.



                  begin program.

                  import spssaux2



                  spssaux2.FindEmptyVars(delete=True)

                  end program.



                  If you don't already have the spssaux2 module installed, you would need to get it from the SPSS Community website or the IBM Predictive Analytics site and save it in the pythonlibsite-packages directory under your Statistics installation.



                  Otherwise, the VALIDATEDATA command, if you have it, will identify the variables violating such rules as maximum percentage of missing values, but you would have to turn that output into a DELETE VARIABLES command. You could also look for variables with zero missing values using, say, DESCRIPTIVES and select out the ones with N=0.






                  share|improve this answer













                  The simplest way would be to use the spssaux2.FindEmptyVars Python function like this.



                  begin program.

                  import spssaux2



                  spssaux2.FindEmptyVars(delete=True)

                  end program.



                  If you don't already have the spssaux2 module installed, you would need to get it from the SPSS Community website or the IBM Predictive Analytics site and save it in the pythonlibsite-packages directory under your Statistics installation.



                  Otherwise, the VALIDATEDATA command, if you have it, will identify the variables violating such rules as maximum percentage of missing values, but you would have to turn that output into a DELETE VARIABLES command. You could also look for variables with zero missing values using, say, DESCRIPTIVES and select out the ones with N=0.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 13 '16 at 0:34









                  JKPJKP

                  5,22295




                  5,22295

























                      1














                      If you've never worked with python in SPSS, here's a way to get the job done without it (not as elegant, but should do the job):



                      This will count the valid cases in each variable, and select only those that have 0 valid cases. Then you'll manually copy the names of these variables into a syntax command that will delete them.



                      DATASET NAME Orig.
                      DATASET DECLARE VARLIST.
                      AGGREGATE /OUTFILE='VARLIST'/BREAK=
                      /**list_all_the_variable_names_here = NU(*FirstVarName to *LastVarName).
                      DATASET ACTIVATE VARLIST.
                      VARSTOCASES /MAKE NumValid FROM *FirstVarName to *LastVarName/INDEX=VarName(NumValid).
                      SELECT IF NumValid=0.
                      EXECUTE.


                      Pause here to copy the remaining names in the list and complete the syntax, then continue:



                      DATASET ACTIVATE Orig.
                      DELETE VARIABLES *paste_here_all_the_remaining_variable_names_from_varlist .


                      Notes:
                      * I put stars where you have to replace my text with your variable names.
                      ** If the variables are neatly named like Q1, Q2, Q3 .... Q1000, you can use the "FirstVarName to LastVarName" form (Q1 to Q1000) instead of listing all the variable names.



                      BTW it is of course possible to do this completely automatically without manually copying those names (using only syntax, no Python), but the added complexity is not worth bothering with for a single use...






                      share|improve this answer






























                        1














                        If you've never worked with python in SPSS, here's a way to get the job done without it (not as elegant, but should do the job):



                        This will count the valid cases in each variable, and select only those that have 0 valid cases. Then you'll manually copy the names of these variables into a syntax command that will delete them.



                        DATASET NAME Orig.
                        DATASET DECLARE VARLIST.
                        AGGREGATE /OUTFILE='VARLIST'/BREAK=
                        /**list_all_the_variable_names_here = NU(*FirstVarName to *LastVarName).
                        DATASET ACTIVATE VARLIST.
                        VARSTOCASES /MAKE NumValid FROM *FirstVarName to *LastVarName/INDEX=VarName(NumValid).
                        SELECT IF NumValid=0.
                        EXECUTE.


                        Pause here to copy the remaining names in the list and complete the syntax, then continue:



                        DATASET ACTIVATE Orig.
                        DELETE VARIABLES *paste_here_all_the_remaining_variable_names_from_varlist .


                        Notes:
                        * I put stars where you have to replace my text with your variable names.
                        ** If the variables are neatly named like Q1, Q2, Q3 .... Q1000, you can use the "FirstVarName to LastVarName" form (Q1 to Q1000) instead of listing all the variable names.



                        BTW it is of course possible to do this completely automatically without manually copying those names (using only syntax, no Python), but the added complexity is not worth bothering with for a single use...






                        share|improve this answer




























                          1












                          1








                          1







                          If you've never worked with python in SPSS, here's a way to get the job done without it (not as elegant, but should do the job):



                          This will count the valid cases in each variable, and select only those that have 0 valid cases. Then you'll manually copy the names of these variables into a syntax command that will delete them.



                          DATASET NAME Orig.
                          DATASET DECLARE VARLIST.
                          AGGREGATE /OUTFILE='VARLIST'/BREAK=
                          /**list_all_the_variable_names_here = NU(*FirstVarName to *LastVarName).
                          DATASET ACTIVATE VARLIST.
                          VARSTOCASES /MAKE NumValid FROM *FirstVarName to *LastVarName/INDEX=VarName(NumValid).
                          SELECT IF NumValid=0.
                          EXECUTE.


                          Pause here to copy the remaining names in the list and complete the syntax, then continue:



                          DATASET ACTIVATE Orig.
                          DELETE VARIABLES *paste_here_all_the_remaining_variable_names_from_varlist .


                          Notes:
                          * I put stars where you have to replace my text with your variable names.
                          ** If the variables are neatly named like Q1, Q2, Q3 .... Q1000, you can use the "FirstVarName to LastVarName" form (Q1 to Q1000) instead of listing all the variable names.



                          BTW it is of course possible to do this completely automatically without manually copying those names (using only syntax, no Python), but the added complexity is not worth bothering with for a single use...






                          share|improve this answer















                          If you've never worked with python in SPSS, here's a way to get the job done without it (not as elegant, but should do the job):



                          This will count the valid cases in each variable, and select only those that have 0 valid cases. Then you'll manually copy the names of these variables into a syntax command that will delete them.



                          DATASET NAME Orig.
                          DATASET DECLARE VARLIST.
                          AGGREGATE /OUTFILE='VARLIST'/BREAK=
                          /**list_all_the_variable_names_here = NU(*FirstVarName to *LastVarName).
                          DATASET ACTIVATE VARLIST.
                          VARSTOCASES /MAKE NumValid FROM *FirstVarName to *LastVarName/INDEX=VarName(NumValid).
                          SELECT IF NumValid=0.
                          EXECUTE.


                          Pause here to copy the remaining names in the list and complete the syntax, then continue:



                          DATASET ACTIVATE Orig.
                          DELETE VARIABLES *paste_here_all_the_remaining_variable_names_from_varlist .


                          Notes:
                          * I put stars where you have to replace my text with your variable names.
                          ** If the variables are neatly named like Q1, Q2, Q3 .... Q1000, you can use the "FirstVarName to LastVarName" form (Q1 to Q1000) instead of listing all the variable names.



                          BTW it is of course possible to do this completely automatically without manually copying those names (using only syntax, no Python), but the added complexity is not worth bothering with for a single use...







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 1 '16 at 8:03

























                          answered Feb 29 '16 at 23:26









                          eli-keli-k

                          4,61283040




                          4,61283040






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35348734%2fdelete-variables-based-on-the-number-of-observations-in-spss%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              The term 'EXEC' is not recognized as the name of a cmdlet Powershell

                              NPM command prompt closes immediately [closed]

                              Error binding properties and functions in emscripten