誕生日からその人の年齢を求めたいのですが、どのようにしたら良いでしょうか。
Microsoft Excelでは、「DATADIF」関数を使用し、開始日と終了日と単位を指定すると年齢を表示できますが、SAS関数に同様の機能がありますか。 探したのですが見当たりませんので教えてください。
SASには、SAS日付値を扱う関数が用意されています。
(例: TODAY, YEAR, MONTH, DAY, WEEKDAY, MDY, INTCK, INTNX)
これらの関数をご使用になると日付の計算をより簡単に行えます。
(SAS日付値とは1960年1月1日から数えた累積日数です。)
年齢の計算には、INTCK関数をご利用になると便利です。
INTCK関数は、二つのSAS日付値の間に何回、年(又は月)を越すかを求めるものです。
下記の使用例をご参照ください。
(実際には一日しか間隔はございませんが、1年と表示されます。)
<プログラム例>
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;
参考:
「SAS® 9.4関数とCALLルーチン リファレンス, 第4版」
http://support.sas.com/documentation/cdl_alternate/ja/lefunctionsref/67960/HTML/default/p1md4mx2crzf...
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
コミュニティの基本的なガイドラインについてご説明します。まずは、こちらをご参照ください。
SAS Support CommunitiesのFAQはヘルプに記載されています。参照方法は、こちらからご確認ください。
Japan SAS Discussionページに質問や意見(メッセージ)を投稿/返信する方法を簡単にご説明します。