無論你是否想取代他們,這是proc format
確實在SAS - 一個值到另一個值映射。
以下是您可能如何做到的。請注意,您不能重用原始3個變量(因爲它們是數字),但如果您確實需要相同的變量名稱,則可以執行rename
和drop
組合。
直接使用format
語句也會直觀地獲得相同的結果(但底層值仍然是數字值)。
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 a
1234 b
2222 c
2938 d
3849 e
9388 f
;;;;
run;
data for_Fmt;
set have_2;
start=numval;
label=charval; *could use rename for these but it makes the last bit more confusing to read;
retain fmtname 'CHARVALF' type 'N';
output;
if _n_=1 then do; *now define the 'other' value (hlo='o') for non-matched records;
hlo='o';
label=' ';
call missing(start); *unnecessary but avoids duplicate start values and 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;
do _i = 1 to dim(Var);
varc[_i] = put(var[_i],CHARVALF1.);
end;
run;
來源
2016-07-25 14:49:40
Joe
你真的需要將它們轉換?或者你只是想讓他們打印更多用戶友好的描述?如果後者那麼這看起來就像是一個完美的FORMAT應用程序。 – Tom