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!
Isn't that anything greater than 000000000000, 12 0's?
if hist12>'000000000000' then ...
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?
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;
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
You could use the INDEXC() function or COUNTC() function.
if index(hist12, '1') then put 'Deliquent';
numdel = countc(hist12,'1');
firstdel = index(hist12,'1') ;
Appreciate all the suggestions. They all worked. The easiest way in my situation is to use countc or index.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: