BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
walterwang
Obsidian | Level 7

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

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?

ballardw
Super User

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 362 views
  • 1 like
  • 3 in conversation