I am trying to extract a Country ID from a numeric product key which has 2 types: 1. A 7-8 digit key with first 2-3 digits signifying country ID. i.e. For US with Country code 36, product key= 36XXXXX For INDIA with Country code 121, product key= 121XXXXX 2. A 13 digit key with 2nd, 3rd , 4th digit signifying country ID i.e. For US , Product key=X036XXXXXXXXX For IN, Product Key= X121XXXXXXXXX Using the following code to get this: data want;
set have;
if length(key)>8 THEN COUNTRY_ID=substr(key), 2,3);
else COUNTRY_ID=substr(key,1,length(key)-5);
run; It works for the 1st type with 7-8 digit product key but not for the longer 13 digit keys. It shows a decimal in the country id i.e. For US, X036XXXX whereas it should be just 36. Do I need to change data type?? Using SAS EG 7.1
... View more