## substr problem

Regular Contributor
Posts: 238

# substr problem

I need the substr to take the first 10 characters of the 12 characters. It is a text and looks similiar to this:

11111111101

I need to drop the 01 off the end.

proc sql;

create table implants.alldrgs_sum as

(select distinct

substr(clm_aud_nbr,2,10) as ClaimNum,

sys_drg_cd,

drg_desc,

alloc_rvnu_cd,

funding,

alloc_allw_amt,

epd_calc_allw_amt,

alloc_net_pd_amt

from implants.implants_aso_alldrgs_copy

group by clm_aud_nbr);

run;

Posts: 3,167

## Re: substr problem

substr(whatevervar, 1,10) ? or if whatevervar is numeric, then try:  substr(put(whatevervar, 12.), 1,10)

Regards,

Haikuo

Super Contributor
Posts: 1,636

## Re: substr problem

data have;

length tt \$ 11;

input id tt;

cards;

1 11111111101

2 21111111101

3 11111111101

4 21111111101

5 31111111101

;

proc sql;

create table want as

select distinct(substr(tt,1,length(tt)-2)) as newtt

from have;

quit;

proc print;run;

Valued Guide
Posts: 765

## Re: substr problem

hi ... you could also use a PUT statement as follows ...

data have;

input id clm_aud_nbr : \$12. @@;

cards;

1 111111111101 2 211111111101 3 111111111101 4 211111111101 5 311111111101

;

proc sql;

create table want as

select id, put(clm_aud_nbr,\$10.) as claimnum from have;

quit;

one advantage is that using PUT gives CLAIMNUM a length of 10

using SUBSTR gives CLAIMNUM a length of 12 (same length as CLM_AUD_NBR)

Discussion stats
• 3 replies
• 412 views
• 1 like
• 4 in conversation