Solved
Contributor
Posts: 71

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.

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

Re: SAS Two dimensional Array

Posted in reply to KafeelBasha

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;

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

Re: SAS Two dimensional Array

Posted in reply to KafeelBasha

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: 71

Re: SAS Two dimensional Array

Posted in reply to Astounding

Thank you very much.

🔒 This topic is solved and locked.

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

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