BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Adnan_Razaq
Calcite | Level 5

Hi All,

 

I need to set up a count of months since an account was last 1+ in arrears.

 

Have

 

Acc    Date     Arrears      

1         Jan        0              

1         Feb        1             

1         Mar        2                   

1         Apr         0   

1         Jun         0                

1         Jul          1  

1         Aug        0 

2         Jan         0 

2         Feb        0 

2         Mar        1

2         Apr         0

2         May        0 

 

How can I set up a flag to do the following

 

Acc    Date     Arrears      Since last 1+

1         Jan        0                    0

1         Feb        1                    0

1         Mar        2                    0

1         Apr         0                    1

1         Jun         0                    2

1         Jul          1                    0

1         Aug        0                    1  

2         Jan         0                    0

2         Feb        0                     0

2         Mar        1                     0

2         Apr         0                     1

2         May        0                     0

 

 

Many Thanks

 

Adnan

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep!

 

data have;
  input Acc  Date $ Arrears;
datalines;
1         Jan        0              
1         Feb        1             
1         Mar        2                   
1         Apr         0 
1         Jun         0                
1         Jul          1  
1         Aug        0 
; 
run;

data want;
  set have;
  retain since_last 0;
  since_last=ifn(_n_=1 or arrears>0,0,since_last+1);
run;

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep!

 

data have;
  input Acc  Date $ Arrears;
datalines;
1         Jan        0              
1         Feb        1             
1         Mar        2                   
1         Apr         0 
1         Jun         0                
1         Jul          1  
1         Aug        0 
; 
run;

data want;
  set have;
  retain since_last 0;
  since_last=ifn(_n_=1 or arrears>0,0,since_last+1);
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1004 views
  • 0 likes
  • 3 in conversation