Calcite | Level 5

## Easy one..Skip Logic

Hi,

I am analyzing survey data which has skip logic. I want to create special missing values for those variables which should have no response.

Essentially I can do this now with If statements but I will have around 1000 statements in total and I do not see this as efficient.

if question1=2 then

question2=._;

if question1=2 then

question3=._;

I am looking for a way to use one statement in which I can list all variables which will be assigned the 'value' of ._. Any help would be appreciated.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Opal | Level 21

## Re: Easy one..Skip Logic

While some folk have said that do over is deprecated, I have always found it quite useful for such tasks.  e.g.:

data have;

input a b c d;

cards;

1 2 1 2

2 3 4 2

1 1 2 1

;

data want;

set have;

array recode a--d;

do over recode;

if recode eq 2 then call missing(recode);

end;

run;

8 REPLIES 8
Onyx | Level 15

## Re: Easy one..Skip Logic

Hi,

If those 'if.. then...'s follow certain rules, then array could be a possible approach. Otherwise, if they are all random assignments, then you are out of luck. So what are the rules here? from your given examples, it is hard for me to fathom.

Haikuo

Calcite | Level 5

## Re: Easy one..Skip Logic

Thanks Haikuo,

The variables which I want to assign ._ all have random names if that's what you're asking?

Could I predefine an array then set the array to ._? How would I define the array?

Chris

Onyx | Level 15

## Re: Easy one..Skip Logic

Chris,

So it sounds like you have a list of those variables, but in what form? if they are already in the form of dataset or macro variable, then you don't have to type them one by one. Give me an example so I can start it for you.

Haikuo

Opal | Level 21

## Re: Easy one..Skip Logic

While some folk have said that do over is deprecated, I have always found it quite useful for such tasks.  e.g.:

data have;

input a b c d;

cards;

1 2 1 2

2 3 4 2

1 1 2 1

;

data want;

set have;

array recode a--d;

do over recode;

if recode eq 2 then call missing(recode);

end;

run;

Calcite | Level 5

## Re: Easy one..Skip Logic

Could I go one step further and ask how to force each of my variables to be numeric or text for the sake of the array?

Opal | Level 21

## Re: Easy one..Skip Logic

Not sure if I understand what you are asking.  An array can only hold character or numeric variables, not both.  Are you looking for something like:?

data have;

input a b \$ c d \$ e f \$ g h \$;

cards;

1 2 1 2 1 2 1 2

2 3 4 2 2 3 4 2

1 1 2 1 1 1 2 1

;

data want;

set have;

array recodec \$ _character_;

array recoden  _numeric_;

do over recodec;

if recodec eq '2' then call missing(recodec);

end;

do over recoden;

if recoden eq 2 then call missing(recoden);

end;

run;

PROC Star

## Re: Easy one..Skip Logic

Well, you can't change a variable that has already been defined.  But you can change the array definitions.  For example:

array recode a-numeric-d;

This array now contains the numeric variables only, beginning with A and ending with D.  Similarly,

array recode2 a-character-d;

This array contains all the character variables only, in that same range.

You can get warning messages if you define an array with 0 elements, and you would have to investigate whether or not those warnings make a difference to you.

Good luck.

Calcite | Level 5

## Re: Easy one..Skip Logic

Thank you very much for the informative replies! Very helpful

Discussion stats
• 8 replies
• 1086 views
• 6 likes
• 4 in conversation