Desktop productivity for business analysts and programmers

Changing ? to missing in all variables (character and numeric)

Accepted Solution Solved
Reply
SAS Employee
Posts: 6
Accepted Solution

Changing ? to missing in all variables (character and numeric)

I am importing some CSV sheets with 60+ variables and the author used ? for missing values so they are imported as ?. How can I simply set all ?s to missing without having to write 60 if-thens?


Accepted Solutions
Solution
‎03-14-2015 09:51 PM
Super Contributor
Posts: 275

Re: Changing ? to missing in all variables (character and numeric)

Something like this.

data want;

  set have;

  array num_vars _numeric_;

  array char_vars _character_;

  do over num_vars;

    if num_vars=? then call missing(num_vars);

  end;

  do over char_vars;

    if char_vars='?' then call missing(char_vars);

  end;

run;

View solution in original post


All Replies
Solution
‎03-14-2015 09:51 PM
Super Contributor
Posts: 275

Re: Changing ? to missing in all variables (character and numeric)

Something like this.

data want;

  set have;

  array num_vars _numeric_;

  array char_vars _character_;

  do over num_vars;

    if num_vars=? then call missing(num_vars);

  end;

  do over char_vars;

    if char_vars='?' then call missing(char_vars);

  end;

run;

SAS Employee
Posts: 6

Re: Changing ? to missing in all variables (character and numeric)

Thanks. That works. The only problem is that num vars are assumed to be character var during import because of instances of ? in them.

Any thoughts how to turn them back to num var after correction?

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 296 views
  • 0 likes
  • 2 in conversation