Reputation: 41
proc fcmp outlib=work.func.conversion;
function upper_vn(province $) $;
length new_province $200;
if province in ("TỈNH QuẢNG NINH", "TỈNH QUẢNG NINH") then new_province = "TỈNH QUẢNG NINH";
if province in ("TỈNH THỪA THIÊN HUẾ","TỈNH THỪA THIÊN-HUẾ","TỈNH THỪA THIÊN-HuẾ") then new_province = "TỈNH THỪA THIÊN HUẾ";
if province in ("TỈNH TiỀN GIANG","TỈNH TIỀN GIANG") then new_province = "TỈNH TIỀN GIANG";
else new_province = province;
return (new_province);
endsub;
run;
options cmplib=(work.func);
data test;
length test_string $ 50;
input test_string & $;
datalines;
"TỈNH THỪA THIÊN-HUẾ"
"TỈNH TIỀN GIANG";
run;
data output;
set test;
length test_string $ 50;
length newprovince $ 50;
newprovince = upper_vn(test_string );
run;
So I create a function in SAS but the result output doesn't return full length of the output string. What could possibly wrong?
Upvotes: 0
Views: 126
Reputation: 121
In addition to Tom's comment above, you need to declare the length of new_province within the function as well as the output length of the function.
proc fcmp outlib=work.func.conversion;
function Unify_Agc(province $) $ 200;
length province new_province $200;
if province in ("TỈNH QuẢNG NINH", "TỈNH QUẢNG NINH") then new_province = "TỈNH QUẢNG NINH";
if province in ("TỈNH THỪA THIÊN HUẾ","TỈNH THỪA THIÊN-HUẾ","TỈNH THỪA THIÊN-HuẾ") then new_province = "TỈNH THỪA THIÊN HUẾ";
if province in ("TỈNH TiỀN GIANG","TỈNH TIỀN GIANG") then new_province = "TỈNH TIỀN GIANG";
else new_province = province;
return (new_province);
endsub;
run;
options cmplib=(work.func);
Upvotes: 2