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

 

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 783 views
  • 0 likes
  • 3 in conversation