69.SAS DATE | TIME | DHMS |HMS|TODAY|DATETIME FUNCTIONS

                        SAS DATE | TIME | DHMS |HMS|TODAY|DATETIME


1.Function: DHMS

Purpose:To create a SAS datetime value from a SAS date value and a value for the hour, minute, and second.

Syntax: DHMS ( DATE , HOUR , MINUTE , SECOND )

date is a SAS date value, either a variable or a date constant.

hour is a numerical value for the hour of the day. If hour is greater than 24, the function will return the appropriate datetime value.

minute is a numerical value for the number of minutes.

second is a numerical value for the number of seconds.

Examples:

 DATE = '02JAN1960'D ,  H = 23 ,  M = 15 ,  S = 30


2.Function: HMS

Purpose: To create a SAS time value from the hour, minute, and second.

Syntax: HMS(hour, minute, second)

hour is the value corresponding to the number of hours.

minute is the value corresponding to the number of minutes.

second is the value corresponding to the number of seconds.

Examples:

H = 1, M = 30, S = 15 


3.Function: DATE and TODAY (equivalent functions)

Purpose: To return the current date.

Syntax: DATE() or TODAY()

Examples:

04JUN2003 

 

4.Function: DATETIME

Purpose: To return the datetime value for the current date and time.

Syntax: DATETIME()

Examples:

04JUN03:20:10:00


5.Function: TIME

Purpose: To return the time of day when the program was run.

Syntax: TIME()

Examples:

20:10:00


Code:

data test;

Date = today();

DT = datetime();

Time = time();

DT2 = dhms(Date,8,15,30);

Time2 = hms(8,15,30);

DOB = '01jan1960'd;

Age = int(yrdif(DOB,Date,'actual'));

format Date DOB date9. DT DT2 datetime. Time Time2 time.;

run;

title "Listing of Data Set TEST";

proc print data=test noobs;

run;


Explanation:

This program was run in the last update of Sas 9.4 so the values are correspond to that date and time September,14,2015.

The variable DT2 is a SAS datetime value created from the current date and specified values for the hour, minute, and second. TIME2 is a SAS time value created from three values for hour, minute, and second.

Finally, the age was computed using the YRDIF function. The INT function was used to compute age as of the last birthday.


OUTPUT:

                                                                   Listing of Data Set TEST


Date DT Time DT2 Time2 DOB Age
14SEP2015 14SEP15:00:10:07 0:10:07 14SEP15:08:15:30 8:15:30 01JAN1960 55

TRY THIS AND COMMENT ...


-->PLEASE READ AND COMMENT THE BLOG...

--PLEASE FOLLOW THE BLOG FOR MORE UPDATES...

--FOLLOW US IN FACEBOOK SASALL4YOU AND JOIN ...

--JOIN US IN FACEBOOK AND TELEGRAM  CHANNEL FOR MORE UPDATES

   CLICK HERE: https://t.me/SasAll4You




Comments