sql - How would I iterate through a list in SAS and translate / replace each piece with an imported mapping? -
i new sas , i'm not sure how go replacing each part of dataset have_1 translation data set (have_2) imported sas.
data have_1 1111 1234 2222 2938 3849 1234 9388 ... 2222 2222 data have_2 1111 1234 b 2222 c 2938 d 3849 e ... 9388 f data want b c d e b f c c
whether or not want replace them, proc format
in sas - maps value value.
here how might that. note cannot reuse original 3 variables (since they're numeric), rename
, drop
combination if wanted same variable names.
using format
statement directly achieve same result visually (but underlying value still numeric one).
data have_1; infile datalines missover; input var1-var3; datalines; 1111 1234 2222 2938 3849 1234 9388 2222 2222 ;;;; run; data have_2; input numval charval $; datalines; 1111 1234 b 2222 c 2938 d 3849 e 9388 f ;;;; run; data for_fmt; set have_2; start=numval; label=charval; *could use rename these makes last bit more confusing read; retain fmtname 'charvalf' type 'n'; output; if _n_=1 do; *now define 'other' value (hlo='o') non-matched records; hlo='o'; label=' '; call missing(start); *unnecessary avoids duplicate start values , less confusing output; output; end; run; proc format cntlin=for_fmt; quit; data want; set have_1; format var1-var3 charvalf1.; *option 1 - visual format only; array var[3]; array varc[3] $; *option 2 - new set of vars w/char vals; _i = 1 dim(var); varc[_i] = put(var[_i],charvalf1.); end; run;
Comments
Post a Comment