|
|
年齢の計算方法
[OS]ALL
[リリース] 6.x, 8.1
[キーワード] base, date, age, datastep, intck
[質問]
誕生日からその人の年齢を求めたいのですが、どのようにしたら良いでしょうか。
[回答]
SASには、SAS日付値を扱う関数が用意されています。 <プログラム例>
data _null_;
year=intck('YEAR', '31Dec1999'd, '1Jan2000'd);
put year=;
run;
<結果> YEAR=1 NOTE: DATA statement は 0.13 秒を使用しました.
上の例では数え年が求められます。
data _null_;
/* 現在の日付 */
current='7SEP2000'd;
/* 誕生日 */
birth='22MAY1973'd;
/* 数え年を求めます */
age=intck('YEAR', birth, current);
/* 今年の誕生日がまだ来ていない場合は、数え年から1を引きます */
if (month(current) < month(birth)) then
age=age - 1;
else if (month(current) = month(birth)) and
day(current) < day(birth) then
age=age - 1;
/* 結果の表示 */
put age=;
run;
[参考]
|
|||||