BookmarkSubscribeRSS Feed
otis
Calcite | Level 5

This attribute, hist12, contains a 12-month history of delinquency. For example, 100000001000 indicates the most recent month and 9 months prior have delinquencies and all other months were current. I need to identify accounts with at least 1 delinquency in the last 12 months. What's the most efficient way to code it? I can use substr function to extract one byte at a time, but I would think there are better ways.

Thanks!

6 REPLIES 6
Reeza
Super User

Isn't that anything greater than 000000000000, 12 0's?

if hist12>'000000000000' then ...

otis
Calcite | Level 5

Thanks. That really helps. One thing I forgot to mention is that there is a value 'Z' represents inactivity. So it could look like: 10000zz00100. Your codes would include accounts with at least one delinquency in last 12 months or at least one inactivity ('Z') in last 12 months. How do I code it so I only have the first set?

Reeza
Super User

compress out the Z's....

Test is just to see the variable, you can delete that line.

data want;

set have;

test=input(compress(hist12, "z"), 12.);

if input(compress(hist12, "z"), 12.)>0 then flag=1;

else flag=0;

run;

Haikuo
Onyx | Level 15

If using compress() as Reeza suggested, you can as well just do the following:

data want;

  set have;

flag=lengthn(compress(a,'z0'))>0;

run;

Haikuo

Tom
Super User Tom
Super User

You could use the INDEXC() function or COUNTC() function.

if index(hist12, '1') then put 'Deliquent';

numdel = countc(hist12,'1');

firstdel = index(hist12,'1') ;

otis
Calcite | Level 5

Appreciate all the suggestions. They all worked. The easiest way in my situation is to use countc or index.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 1942 views
  • 0 likes
  • 4 in conversation