How to Apply and IF Statement to Multiple Similar Fields

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

How to Apply and IF Statement to Multiple Similar Fields

f

I have multiple fields named M_0, M_1, M_2, M_3, Ect...

Some of the fields have blanks in which I need to update to 0.

I have been unsuccessfully trying to use an Array to cahnge all of the field that start "M_", that are null, to a 0.

Does anyone have some sample code where they encountered this? If so could you provide me with it so I can get my own working?

Thanks!


Accepted Solutions
Solution
‎03-13-2014 04:28 PM
PROC Star
Posts: 7,363

Re: How to Apply and IF Statement to Multiple Similar Fields

data want;

  set have;

  array m(*) m_:;

  do _n_=1 to dim(m);

    m(_n_)=ifn(missing(m(_n_)),0,m(_n_));

  end;

run;

View solution in original post


All Replies
Solution
‎03-13-2014 04:28 PM
PROC Star
Posts: 7,363

Re: How to Apply and IF Statement to Multiple Similar Fields

data want;

  set have;

  array m(*) m_:;

  do _n_=1 to dim(m);

    m(_n_)=ifn(missing(m(_n_)),0,m(_n_));

  end;

run;

☑ This topic is SOLVED.

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

Discussion stats
  • 1 reply
  • 165 views
  • 0 likes
  • 2 in conversation