From: rocketD on
Hello,

I have a dataset from a survey that is receiving new participants
continuously, and I add those records to the database once a week or
so. Several of the questions have answers that should skip other
questions, and instead of them having zero values, I want to assign a
999 (for n/a) to those questions. Unfortunately the software I have
to use for the surveys doesn't allow this (or much of anything,
really).

As an extreme example, the first question is Consent - 0 for no, 1 for
yes. If Consent = 0, then I want all other questions for that record
to have a value of 999. There are 175 variables and I really don't
want to do 174 IF statements, even if I can do it fairly quickly with
help from Excel. I was wondering if I can set up a do loop or
something else to run and replace all values with a different value
based on a condition, record by record?

Can anyone provide any ideas? I'm very amateur at SAS but I can
learn.

Thanks!
From: Alex_DPC on
On Apr 1, 12:49 am, rocketD <dar...(a)gmail.com> wrote:
> Hello,
>
> I have a dataset from a survey that is receiving new participants
> continuously, and I add those records to the database once a week or
> so.  Several of the questions have answers that should skip other
> questions, and instead of them having zero values, I want to assign a
> 999 (for n/a) to those questions.  Unfortunately the software I have
> to use for the surveys doesn't allow this (or much of anything,
> really).
>
> As an extreme example, the first question is Consent - 0 for no, 1 for
> yes.  If Consent = 0, then I want all other questions for that record
> to have a value of 999.  There are 175 variables and I really don't
> want to do 174 IF statements, even if I can do it fairly quickly with
> help from Excel.   I was wondering if I can set up a do loop or
> something else to run and replace all values with a different value
> based on a condition, record by record?
>
> Can anyone provide any ideas?  I'm very amateur at SAS but I can
> learn.
>
> Thanks!

Hi rocketD,

I work with survey data every day and your scenario sounds more than
familiar.

I would suggest that you make yourself familiar with arrays to deal
with this. In the case you described a simple solution could look like
this:

data want (drop = i) ;
set have ;

array all_resp (*) <list of all your response variables>;

if not Consent then do i = 1 to dim( all_resp ) ;
all_resp(i) = 999 ;
end;
run;

For other filter variables just replace the condition "not Consent"
and specify the correct set of dependent variables for the array.

Some more hints about filter-dependent blocks:
- Use a SAS numeric missing value instead of 999, e.g. ".A". Unlike
SPSS, SAS does not know the concept of user-defined missing values.
But when you create the sum out of 2 "missing" variables, you probably
would prefer a to get a missing value instead of 1998.
- What if the respondent omitted the filter variable? In such cases we
recode the dependent variables to a special missing value indicating
"Omitted" for the dependent variables, too.
- What if the respondent replied negatively to the filter variable,
but actually answered the dependent variables? This is not too
uncommon in paper questionnaires. In some cases it might be a good
idea to recode the filter to positive depending on the dependent
variables instead the other way round. This would of course make no
sense for "Consent".
- Be very careful when you deal with nested filter-dependent blocks.
I.e., what if a dependent variable is also a filter variable? Maybe
you don't have such a case, but when you do, take care to do the edits
in the correct order. For instance if the first filter is negative,
then you recode all its dependent variables. One of the dependent
variables is also a filter variable and could now be recoded from a
valid value to a missing value. As you see, it makes a difference if
you treat them bottom-up or top-down.

OK, enough for now. Good luck with your task!

Cheers,
Alex
From: montura on
Assign a missing value for data not collected.
Assign a "NA" to another variable to designate the absence value as
not needed, due to a data independence/dependency.

array all_resp (*) <list of all your response variables>;
array all_flags(*) <....>;

From: tanwan on
Also be on the look out for typos. Suppose consent is 0, but the rest
of the questions are populated with logical data, (e.g. Name, age, and
the proper skips were followed!!!) then you can guess that the consent
question was keyed in wrongly. In that case you might want NOT to lose
that data.

T!