I have a survey dataset.
such as
Q1 Q2 Q3 ...
0.5 yes most
0.1 no some
….
Some one just answer some questions. for example, stop at Q15; stop at Q23.
Is there any best way to identify these people?
The fun part of this type of question and surveys can revolve around skip patterns.
The following could be a starting point.
data want; set have; array num _numeric_; /* instead of _numeric_ should actually be a list of the questions with numeric response values*/ array c _character_;/* instead of _character_ should actually be a list of the questions with character response values*/ length lastnumvar lastcharvar $ 32; do i= dim(num) to 1; if not missing( num[i]) then do; lastnumvar= vname(n[i]); end; end; do i= dim(c) to 1; if not missing( c[i]) then do; lastnumvar= vname(c[i]); end; end; run;
You will want to look up VARIABLE LIST to find ways to list your variables. If ALL of the question variables were the same answer type, numeric or character, and the names all start with Q then you could use a list like Q: ; but with apparent mixes of numeric and character you need to process each variable type separately.
Lists could be individual variable names: Q1 Q10 Q11 Q12
Range if there are numeric suffixes in order: Q1 Q10 - Q12
Or adjacent in the data set : Q1 Q10A -- Q12D . This could be that you have multiple part answers to Q10 named something like Q10A Q10B Q10C .. and all columns through Q12D are of the same type for processing. Note 2 dashes for the list.
You can mix as shown single variable names , ranges and intervals but you don't want the same variable to appear twice.
The above code creates two variables that have the name of the last variable of each type that have a response. Hopefully. If you have added non-question variables or other variables are in your data other than questions then you likely want to subset the data to only questions for this purpose.
Or see if your survey software tracks and can report the last question answered. This may be a feature available if the software has options that allow continuing an interrupted survey.
If you're after code then please provide sample data in the form of a working SAS datastep which fully supports your question. Then show us the desired result based on the sample data.
For how I understand your question based on what you've provided: Couldn't you just search for missings? Like checking if the last n answers are missing?
The fun part of this type of question and surveys can revolve around skip patterns.
The following could be a starting point.
data want; set have; array num _numeric_; /* instead of _numeric_ should actually be a list of the questions with numeric response values*/ array c _character_;/* instead of _character_ should actually be a list of the questions with character response values*/ length lastnumvar lastcharvar $ 32; do i= dim(num) to 1; if not missing( num[i]) then do; lastnumvar= vname(n[i]); end; end; do i= dim(c) to 1; if not missing( c[i]) then do; lastnumvar= vname(c[i]); end; end; run;
You will want to look up VARIABLE LIST to find ways to list your variables. If ALL of the question variables were the same answer type, numeric or character, and the names all start with Q then you could use a list like Q: ; but with apparent mixes of numeric and character you need to process each variable type separately.
Lists could be individual variable names: Q1 Q10 Q11 Q12
Range if there are numeric suffixes in order: Q1 Q10 - Q12
Or adjacent in the data set : Q1 Q10A -- Q12D . This could be that you have multiple part answers to Q10 named something like Q10A Q10B Q10C .. and all columns through Q12D are of the same type for processing. Note 2 dashes for the list.
You can mix as shown single variable names , ranges and intervals but you don't want the same variable to appear twice.
The above code creates two variables that have the name of the last variable of each type that have a response. Hopefully. If you have added non-question variables or other variables are in your data other than questions then you likely want to subset the data to only questions for this purpose.
Or see if your survey software tracks and can report the last question answered. This may be a feature available if the software has options that allow continuing an interrupted survey.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.