SAS Two dimensional Array

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

SAS Two dimensional Array

I have written the below code

data want;
set want;
array x(2,3)$ Day5-Day7 City1-City3;
array m(2);
do i=1 to 2;
do j=1 to 3;
m(i)=0;
if x(i,j)='NA' then m(i)=m(i)+1;
end;
end;
total_mis=m1+m2;
drop i;
drop j;
run;

 

Logically, m1 is number of missing values across days and m2 number of missing values across cities. But I am getting other way. Have a look at the image below.

 

For the first record I should get m1=2 and m2=2.

missing.png

 

Please help me regarding this.


Accepted Solutions
Solution
‎03-24-2016 12:21 PM
Super User
Posts: 5,367

Re: SAS Two dimensional Array

These statements are in the wrong order:


do j=1 to 3;
m(i)=0;

 

You end up re-setting m(i) too many times.  Just reverse them:

 

m(i)=0;
do j=1 to 3;

View solution in original post


All Replies
Solution
‎03-24-2016 12:21 PM
Super User
Posts: 5,367

Re: SAS Two dimensional Array

These statements are in the wrong order:


do j=1 to 3;
m(i)=0;

 

You end up re-setting m(i) too many times.  Just reverse them:

 

m(i)=0;
do j=1 to 3;

Contributor
Posts: 70

Re: SAS Two dimensional Array

Thank you very much.

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 253 views
  • 1 like
  • 2 in conversation