An alternative to formats, which can be helpful in certain circumstances is to use datasets. The example below shows the ability to generate any form of code to apply a codelist to a value. (Note the code here is only for the substr() example given, if its more complicated then you might need to add more code):
data have; input account_id $10.; datalines; 2BCD 2ACD AA2CDBB 2CDERT ABCD ; run; data codelist; length code long_value $10 logic $50; code="2BCD"; long_value="A"; logic="account_id"; output; code="2ACD"; long_value="B"; logic="account_id"; output; code="2CD"; long_value="C"; logic="substr(account_id,1,3)"; output; run; /* This is where the code is generated */ data _null_; set codelist end=last; if _n_=1 then call execute('data have; set have; length long_value $10;'); call execute(' if '||strip(logic)||'="'||strip(code)||'" then long_value="'||strip(long_value)||'";'); if last then call execute('run;'); run;
... View more