Desktop productivity for business analysts and programmers

Finding results with a length > 3

Reply
Occasional Contributor
Posts: 12

Finding results with a length > 3

Hi.  I am working with a dataset where I need to find the length of one of the variables is greater than 3.  I was successful in writing the code where the length = 3.  Now I need the rest.  Could someone help me?

 

Thanks.

 

 

proc sql;
create table DOJ.PMHS_MS_CC as
select length(a.ClaimScheduleId,3) as ClaimScheduleId, b.ScheduleName, b.ScheduleTypeCode
from doj.new_Qtrly_ClaimSchedule a
inner join doj.Cur_ClmSchNmTy b
on a.ClaimScheduleId = b.FeeScheduleId
where b.ScheduleTypeCode in ('MS', 'CC')
;quit;

Occasional Contributor
Posts: 12

Re: Finding results with a length > 3

I was wrong. My original code didn't work.  I'm looking for ClaimScheduleId where the length = 3 and the matching ScheduleName and ScheduleTypeCode.  Then I need to make another table where the ClaimScheduleId length >3 and the matching ScheduleName and ScheduleTypeCode.  Could someone help me?  Thanks.

Grand Advisor
Posts: 10,251

Re: Finding results with a length > 3

[ Edited ]

Are you trying to find one or more variables in a dataset whose defined length is greater than 3 or are you trying to find values of a specific variable that have a length greater than 3?

 

If looking for values then finding values with length 3:

proc sql;
   create table DOJ.PMHS_MS_CC as
   select ClaimScheduleId, b.ScheduleName, b.ScheduleTypeCode
   from doj.new_Qtrly_ClaimSchedule a
   inner join doj.Cur_ClmSchNmTy b
   on a.ClaimScheduleId = b.FeeScheduleId
   where b.ScheduleTypeCode in ('MS', 'CC') 
         and length(ClaimScheduleId)=3
   ;
quit;

 to find > 3 change the = to > in the last comparison

Occasional Contributor
Posts: 12

Re: Finding results with a length > 3

I am trying to find the values of the specific variable ClaimScheduleId that has a length greater than 3.

Trusted Advisor
Posts: 1,061

Re: Finding results with a length > 3

I think this is what you're after:

 

data have;
length ClaimScheduleId $8;
input ClaimScheduleId;
cards;
AB
ABC
ABCD
ABCDE
run;
proc sql noprint;
create table want as
select * from have
where length(strip(ClaimScheduleId)) >= 3;
quit;

 

Tom

 

 

 

Ask a Question
Discussion stats
  • 4 replies
  • 206 views
  • 0 likes
  • 3 in conversation