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;
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.
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
I am trying to find the values of the specific variable ClaimScheduleId that has a length greater than 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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.