|
I have a case where an already defined variable has a character length of 15-digit, but these values are not constant. Some of which are 6-digit, 7-digit, 8-digit and 15-digit. I've used the SUBSTR function to match merge with my file to the master file (PROVIDERDATA). The SUBSTR function returns a part of the string with the specified length beginning at the specified position. Therefore, if I code as substr(providernumber,1,6)='400573' it selects providers with number starts with 400573. Now the problem is my file will be inaccurate because it also selects provider numbers such as 4005737, or 40057325, or 40057359 N01, which all I want is provider number 400573.
In order to prevent extracting those unwanted provider numbers, I've used the LENGTH function instead. Using the LENGTH function, it sets a memory length of the string argument of a character variable. It reads the actual length of the provider number to pull out accurately from the PROVIDERDATA.
|
data myfile;
INPUT Provider $ 15.
;
CARDS;
188993 N01
111555801 005
400573
;
run;
|
proc sql;
create table workdata as
select a.provnum, a.memberid, b.provider,
length(provnum),
length(provider)
from PROVIDERDATA a, myfile b
where a.provnum=b.provider
;
proc print data=workdata;
run;
|
SAS Output
Obs PROVNUM THRUDATE Provider _TEMA001 _TEMA002
1 111555801 005 20030501 111555801 005 15 15
2 188993 N01 20030501 188993 N01 15 15
3 400573 20030501 400573 6 6
|
|