BookmarkSubscribeRSS Feed

Macro Variables of Date and Time

Started ‎07-03-2018 by
Modified ‎07-03-2018 by
Views 34,456

 

%let WeekDate  = %sysfunc(date(),weekdate29.) ;
%let DateCCYY  = %sysfunc(date(),year4.)      ;
%let DateMonth = %sysfunc(date(),MonName9.)   ;   %*September:9;
%let Date_MM   = %sysfunc(date(),Month2.)     ;   %*01:12;
%let Date_DD   = %sysfunc(date(),Day2.)       ;   %*01:31;
%let Date_Day  = %sysfunc(date(),downame9.)   ;   %*Wednesday:9;
%let DateJul   = %sysfunc(date(),julian7.)    ;   %*ccYYddd;
%let DateJulDay= %sysfunc(date(),julday3.)    ;   %*ddd;
%let Date_Qtr  = %sysfunc(date(),qtr1.)       ;   %*1:4;
%let Time      = %sysfunc(time(),time8.0)     ;   %*HH:MM:SS;
%let Time_HH   = %scan(&Time.,1,:)            ;
%let Time_MM   = %scan(&Time.,2,:)            ;
%let Time_SS   = %scan(&Time.,3,:)            ;
%let TimeAMPM  = %sysfunc(time(),timeAmPm8.0) ;   %*HH:MM AM;
 
%put Weekdate  = &WeekDate  ;
%put DateCCYY  = &Dateccyy  ;
%put DateMonth = &DateMonth ;
%put Date_MM   = &Date_mm   ;
%put Date_DD   = &Date_dd   ;
%put Date_Day  = &Date_Day  ;
%put DateJul   = &DateJul   ;
%put DateJulDay= &DateJulDay;
%put Date_Qtr  = &Date_Qtr  ;
%put Time      = &Time      ;
%put Time_HH   = &Time_hh   ;
%put Time_MM   = &Time_mm   ;
%put Time_SS   = &Time_ss   ;
%put TimeAMPM  = &TimeAmpm  ;

 

Log:

 

24   %put Weekdate  = &weekdate  ; Weekdate  = Wednesday, November 20, 2002
25   %put DATECCYY  = &dateccyy  ; DATECCYY  = 2002
26   %put DATEMONTH = &datemonth ; DATEMONTH = November
27   %put DATE_MM   = &date_mm   ; DATE_MM   = 11
28   %put DATE_DD   = &date_dd   ; DATE_DD   = 20
29   %put DATE_DAY  = &date_day  ; DATE_DAY  = Wednesday
30   %put DATEJUL   = &datejul   ; DATEJUL   = 2002324
31   %put DATEJULDAY= &datejulday; DATEJULDAY= 324
32   %put DATE_QTR  = &date_qtr  ; DATE_QTR  = 4
33   %put TIME      = &time      ; TIME      = 15:24:01
34   %put TIME_HH   = &time_hh   ; TIME_HH   = 15
35   %put TIME_MM   = &time_mm   ; TIME_MM   = 24
36   %put TIME_SS   = &time_ss   ; TIME_SS   = 01
37   %put TIMEAMPM  = &timeampm  ; TIMEAMPM  = 3:24 PM

 

 

 

see also:

 

 

%Let StDate = &SysDate.;
%*Let StDate = %sysfunc(date(),yymmddn8.);
%Put StDate: &StDate.:
 
%let DatePart  = %sysfunc(datepart(%substr(&SysProcessId.,1,16)x));
%let Year      = %sysfunc(year(&Datepart.));
%let Month     = %sysfunc(putn(&Datepart.,  month2.));
%let Month     = %sysfunc(putn(&Month.   ,      z2.));
%let MonthName = %sysfunc(putn(&Datepart.,monname3.));
%let Day       = %sysfunc(putn(&Datepart.,     day.));
%let Day       = %sysfunc(putn(&Day.     ,      z2.));
 
%Put MyFormatedDate: &Year._&Month.&MonthName.&Day.

 

Thanks to Ronald Fehd for publishing this on sasCommunities.org!

 

Version history
Last update:
‎07-03-2018 10:59 AM
Updated by:
Contributors

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags