Easy one..Skip Logic

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

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


Accepted Solutions
Solution
‎05-29-2012 09:15 AM
PROC Star
Posts: 7,473

Re: Easy one..Skip Logic

Posted in reply to Theriault_SAS

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;

View solution in original post


All Replies
Respected Advisor
Posts: 3,156

Re: Easy one..Skip Logic

Posted in reply to Theriault_SAS

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

Occasional Contributor
Posts: 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

Respected Advisor
Posts: 3,156

Re: Easy one..Skip Logic

Posted in reply to Theriault_SAS

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

Solution
‎05-29-2012 09:15 AM
PROC Star
Posts: 7,473

Re: Easy one..Skip Logic

Posted in reply to Theriault_SAS

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;

Occasional Contributor
Posts: 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?

PROC Star
Posts: 7,473

Re: Easy one..Skip Logic

Posted in reply to Theriault_SAS

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;

Super User
Posts: 5,504

Re: Easy one..Skip Logic

Posted in reply to Theriault_SAS

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.

Occasional Contributor
Posts: 5

Re: Easy one..Skip Logic

Posted in reply to Theriault_SAS

Thank you very much for the informative replies! Very helpful

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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