Conditional Processing in an Array

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

Conditional Processing in an Array

data sales2;

set sales;

array sls{*} &week_vars;

do i=1 to 3;

if sls{i} = 0 then flag = 1;

end;

run;

I want only the 3rd row with all zeroes to be flag=1. Can it be done through arrays or some other function ?

I don't want to put multiple if conditions..

example.png


Accepted Solutions
Solution
‎03-03-2015 04:16 PM
Respected Advisor
Posts: 4,958

Re: Conditional Processing in an Array

Are you looking for zeroes or are you missing for missing values?  They're different.

What should happen if two variables are zero, and the third variable is missing?  Should FLAG be 0 or 1?

The programming is easy.  Defining the requirements is harder.  One possibility:

data sales2;

set sales;

array sls {*} &week_vars;

flag=1;

do i=1 to dim(sls);

   if sls{i} ne 0 then flag=0;

end;

run;

Good luck.

View solution in original post


All Replies
Super Contributor
Posts: 275

Re: Conditional Processing in an Array

data sales2;

set sales;

array sls{*} &week_vars;

if nmiss(of sls(*))=dim(sis) then flag = 1;

run;

Solution
‎03-03-2015 04:16 PM
Respected Advisor
Posts: 4,958

Re: Conditional Processing in an Array

Are you looking for zeroes or are you missing for missing values?  They're different.

What should happen if two variables are zero, and the third variable is missing?  Should FLAG be 0 or 1?

The programming is easy.  Defining the requirements is harder.  One possibility:

data sales2;

set sales;

array sls {*} &week_vars;

flag=1;

do i=1 to dim(sls);

   if sls{i} ne 0 then flag=0;

end;

run;

Good luck.

Contributor
Posts: 36

Re: Conditional Processing in an Array

I think nmiss is looking for missing values. Here I am checking for zeroes. That's why flag is not 1 for any row. As none of the rows are missing any data.

Super Contributor
Posts: 275

Re: Conditional Processing in an Array

so if all 0, replace with

if sum(of sls(*))=0 then flag = 1;

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 205 views
  • 0 likes
  • 3 in conversation