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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.