BookmarkSubscribeRSS Feed
Laurel
Obsidian | Level 7

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;

4 REPLIES 4
Laurel
Obsidian | Level 7

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.

ballardw
Super User

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

Laurel
Obsidian | Level 7

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

TomKari
Onyx | Level 15

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

 

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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