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

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
art297
Opal | Level 21

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

8 REPLIES 8
Haikuo
Onyx | Level 15

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

Theriault_SAS
Calcite | Level 5

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

Haikuo
Onyx | Level 15

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

art297
Opal | Level 21

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;

Theriault_SAS
Calcite | Level 5

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?

art297
Opal | Level 21

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;

Astounding
PROC Star

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.

Theriault_SAS
Calcite | Level 5

Thank you very much for the informative replies! Very helpful

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 8 replies
  • 844 views
  • 6 likes
  • 4 in conversation