I work with survey data and we have a short and a long survey. The long survey contain everything the short survey has with additional questions. If a person completes the short survey we want to set all of the other variables in the dataset for them to special missing, something like .l . We also have a variable to indicate the type of survey. Is there an easy way to do this? Thank you for your help.
Easiest might be an array of the response variables you want to set and in a data step:
supposing that questions q23-q50 are the ones you need to set special missing then:
array NA q23-q50;
do i=1 to dim(NA);
NA[i] = .i;
end;
drop i;
Text variable don't use special missing though.
Easiest might be an array of the response variables you want to set and in a data step:
supposing that questions q23-q50 are the ones you need to set special missing then:
array NA q23-q50;
do i=1 to dim(NA);
NA[i] = .i;
end;
drop i;
Text variable don't use special missing though.
Hmm..That code works the only problem is I have about 300 variables that are not on the short survey but 78 on the short survey. Is there a way to reverse it so I include the variable names from the short survey?
Actually, I was able to get it to work. I added in the following:
if short[i]=. then short[i]=.l;
Thank you for your help!
@rfarmenta wrote:
Actually, I was able to get it to work. I added in the following:
if short[i]=. then short[i]=.l;
Thank you for your help!
Be careful with this approach if you have skip patterns in the survey data or other missing values that are not due to the survey length. You may generate special missing when not intended.
Thank you. The skip patterns is not an issues because we are going to code those as special missing separately. I did realize that my code does not work for what I want though. Are there any other ways to do this? Otherwise I will have to just include all of the variable names. Thank you!
It may help to use variable lists if your variable names are amenable, such as my example. If you have blocks of questions that all the names that start with some common stem that you need to address then you can use something like:
array NA qabc: qpdq: ;
to shorten the amount of code you need to write. The above would place all variables whose names that start with qabc and qpdq into the array but not those that start with qabb or qpdm for instance.
or if the variables you need appear in order you can use the -- in the list to specify variables from to such as
array NA qabc -- qpdq; which would include the variables in order from qabc to qpdq.
You can mix these (carefully) or use multiple lists. For instance if you have blocks of questions in your long survey such that only the first question was asked in the short then array definiton might look like
array NA block1Q2 -- block1Qn block2Q2 -- block2Qn ; Where block1q2 means the second question (or the first unasked in the short form) and block1Qn means the last unasked within that section of questions.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.