I have a column of data with character-formatted numbers, e.g. the value for a record could be "1, 2, 3, 10, 12". These numbers represent a character label, e.g. 1=One, 2=Two, 3=Three, 10=Ten, 12=Twelve. I am trying to use TRANWRD to replace the numbers with the character labels:
char_data=tranwrd(char_data,'1','One');
char_data=tranwrd(char_data,'2','Two');
char_data=tranwrd(char_data,'3','Three');
char_data=tranwrd(char_data,'10','Ten');
char_data=tranwrd(char_data,'12','Twelve');
What I end up with is "One, Two, Three, One0, OneTwo" because I guess SAS is not treating the original 'numbers' as distinct values but rather using the first number and replacing that first (e.g. in the Ten and Twelve examples).
Any way around this?
data have;
length char_data $20.;
input char_data $;
datalines;
1,2,3,10,12
;
run;
data want;
length char_data $50.; format char_data $50.; informat char_data $50.;
set have;
char_data=tranwrd(char_data,'1','One');
char_data=tranwrd(char_data,'2','Two');
char_data=tranwrd(char_data,'3','Three');
char_data=tranwrd(char_data,'10','Ten');
char_data=tranwrd(char_data,'12','Twelve');
run;
... View more