BookmarkSubscribeRSS Feed
TanviG
Fluorite | Level 6

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.

 

1 REPLY 1
PGStats
Opal | Level 21

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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