I have a survey based data with each row representing a particular respondent and each column representing a response for a particular question in the survey. I have a dataset 72 columns and 2417 rows. For each row, I want to find the number of missing values for each row. What I am basically trying to assess is what % of missing values there are in each row.
COMPUTE counting_var = 0.
LOOP #i = 1 TO NCOLS(Dataset1).
DO IF (MISSING(Dataset1(#i))).
counting_var = counting_var + 1.
END IF.
END LOOP.
counting_var = counting_var/NCOLS(Dataset1)
EXECUTE.
This code is written using SPSS syntax. Through this code, I am trying to find the percent of survey questions a particular respondent has answered. If all the columns for a particular row are filled, it means that the respondent has answered all the questions. However, this code is not working as I expect and is simply creating a new column called counting_var and filling it with 0s. I would be grateful if someone could help me fix this code. Unfortunately, I can only do this in SPSS syntax and no other programming language.
SPSS has a function
nmissthat will get you the number of missing values in a row without a loop. Assuming all the variables betweenvar1andvar72in the function are numerical, and consecutive in the data, this should work for you:If you do have string variables in between, the following approach will work better: