1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SASの日付フォーマット

Posted at

備忘録。
各日付の取得とマクロ変数への格納。

日付フォーマット

data _null_ ;
  * 基準日 ;
  base_date = today() ;

  * 週初、月初、月末、年初 ;
  StartOfWeek  = intnx('week' , base_date, 0, 'BEGINNING') ;
  StartOfMonth = intnx('month', base_date, 0, 'BEGINNING') ;
  EndOfMonth   = intnx('month', base_date, 0, 'END') ;
  StartOfYear  = intnx('year' , base_date, 0, 'BEGINNING') ;

  * 基準日の四半期の開始日 ;
  StartOfQtr = yyq(year(base_date), qtr(base_date)) ;
  
  * 前四半期の開始日、終了日 ;
  if qtr(base_date) = 1 then StartOfPrevQtr = yyq(year(base_date)-1, 4) ;
  else StartOfPrevQtr = yyq(year(base_date), qtr(base_date)-1) ;

  EndOfPrevQtr = yyq(year(base_date), qtr(base_date)) -1 ;

  * 出力フォーマット ;
  * 01APR2019 ;
  call symput('base_date'      , put(base_date      , date9.)) ;

  * yymm形式 1904 ;
  call symput('yymm'           , put(base_date      , yymmdd4. )) ;

  * 区切り文字なし20190401 ;
  call symput('StartOfWeek'    , put(StartOfWeek    , yymmddn8.)) ;

  * スラッシュ区切り 2019/04/01 ;
  call symput('StartOfMonth'   , put(StartOfPrevQtr , yymmdds10.)) ;
  call symput('EndOfMonth'     , put(EndOfMonth     , yymmdds10.)) ;
  
  * ハイフン区切り 2019-04-01 ;
  call symput('StartOfYear'    , put(StartOfYear    , yymmdd10.)) ;
  call symput('StartOfQtr'     , put(StartOfQtr     , yymmdd10.)) ;
  call symput('StartOfPrevQtr' , put(StartOfPrevQtr , yymmdd10.)) ;
  call symput('EndOfPrevQtr'   , put(EndOfPrevQtr   , yymmdd10.)) ;
run ;

日時フォーマット

data _null_ ;
  base_dt = datetime() ;
  * 2019/04/01 00:00:00 ;
  call symput('base_dt'   , put(base_dt , nldatm20.)) ;
run ;
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?