Help using Base SAS procedures

help on coding

Reply
Occasional Contributor
Posts: 7

help on coding

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!

Super User
Posts: 19,868

Re: help on coding

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

if hist12>'000000000000' then ...

Occasional Contributor
Posts: 7

Re: help on coding

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?

Super User
Posts: 19,868

Re: help on coding

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;

Respected Advisor
Posts: 3,156

Re: help on coding

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

Super User
Super User
Posts: 7,076

Re: help on coding

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

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

numdel = countc(hist12,'1');

firstdel = index(hist12,'1') ;

Occasional Contributor
Posts: 7

Re: help on coding

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

Ask a Question
Discussion stats
  • 6 replies
  • 248 views
  • 0 likes
  • 4 in conversation