Desktop productivity for business analysts and programmers

Array problem?

Reply
Occasional Learner
Posts: 1

Array problem?

Hi,

 

Here is the explaination of my dataset. Data contains 62 variables. One is unique key as account id and 60 variables are some monthly recovery amounts. the last variable is Total Loss. I want to know all default accounts monthly basis. For this, I created one array of recoveries which is the cumulative sum of months. I am facing problem in creating this array. 

 

data test;
set recovery;
array month{60} nm_1-nm_60;
array recovery{60);
do i=1 to 60;
if _n_=1 then do;
Recovery(i)=month(i);
end;
else do;
Recovery(i)= Sum(month(i),Recovery(i-1));
end;
end;
run;

 

after this I want to check the condition in do loop

data test;

set recovery;

do i=1 to 60;

If Recovery(i) < total_loss then output(i);

end;

run;

 

Can you please help me with the code.

 

Respected Advisor
Posts: 4,971

Re: Array problem?

[ Edited ]

Make SAS retain the values of recovery array elements between observations by giving an initial value to the array

 

array recovery{60} (60*0);

 

You must also define the array in your second datastep. You don't say what the final dataset is supposed to be. Now, it will contain the whole recovery array, repeated for every element that is less than total_loss.

PG
Ask a Question
Discussion stats
  • 1 reply
  • 134 views
  • 0 likes
  • 2 in conversation