Tải bản đầy đủ - 0 (trang)
2 Extracting Pieces from SAS Date, Time, and Datetime Values

2 Extracting Pieces from SAS Date, Time, and Datetime Values

Tải bản đầy đủ - 0trang

year from a SAS date



JULDATE7("09MAY2014"d) =



value. This always



2014129



returns a seven-digit



JULDATE7("09MAY1890"d) =



number, regardless of



1890129



the year.

MONTH(arg)



Extracts the numerical



MONTH("22AUG2015"d) = 8



month from a SAS date

value.

QTR(arg)



Extracts the quarter of



QTR("8JAN2013"d) = 1



the year from a SAS

date value.

WEEK(arg)



Extracts the week



WEEK("02JAN2005"d) = 1



number from a SAS

date value, where

Sunday is the first day

of the week, which is

the "U" algorithm. This

function has been

augmented in SAS

versions 9.1.3 and

above by the

WEEK(arg,descriptor)

function described

immediately below.

(Version 9.1.3 and



Extracts the week number from a SAS date value. descriptor



up)



can be "U," "V," or "W" (case-insensitive), and it refers to



WEEK(arg,descriptor) the algorithm used to calculate the first week of the year.

The U algorithm



WEEK("02JAN2005"d,"U") = 1.



calculates weeks based January 2, 2005 was a Sunday, so



on Sunday being the



the first week of the year has



first day of the week.

The V algorithm



started.

WEEK("02JAN2005"d,"V") = 53.



calculates weeks to the This week is defined as being the

ISO standard. Monday



53rd week in 2004, because it



is the first day of the



doesn't contain the first Monday



week, and the first



or Thursday of the year.



week of the year is

defined as the one that

contains both January

4 and the first

Thursday of the year.

The W algorithm



WEEK("02JAN2005"d,"W") = 0.



calculates weeks based The year 2005 has started, but

on Monday being the



weeks are calculated with Monday



first day of the week



as the first day of the week.



without restriction.



Therefore, the first week of 2005

doesn't start until January 3,

2005, so this is week 0 of 2005.



WEEKDAY(arg)



Extracts the number of WEEKDAY("14APR2011"d) = 4

the day of the week,



(Wednesday, April 14, 2011)



where Sunday=1,

Monday=2, and so on

from a SAS date value.

YEAR(arg)



Extracts the year from



If OPTIONS YEARCUTOFF=1920;



a SAS date value. If



YEAR("19JUL10"d) = 2010;



you use a date



YEAR("19JUL1910"d) = 1910



constant (as in the

example) and not a

SAS date value, it is



important to

remember that the

YEARCUTOFF=

option affects twodigit years.

Table 5.3: Functions Returning a Datetime Component and Requiring a SAS Datetime Value as an Argument



Function Name Explanation



Example



DATEPART(arg) Extracts the date from a



DATEPART('21MAR2012:17:07:00'dt)



SAS datetime value as a



= 19073 (March 21, 2012)



SAS date value.

TIMEPART(arg) Extracts the time portion

from a SAS datetime



TIMEPART("06SEP2012:13:36:33"dt)

= 48993 (1:36:33 PM)



value as a SAS time

value.



Table 5.4: Functions Returning a Time Component and Requiring a SAS Time Value as an Argument



Function

Name



Explanation



Example



HOUR(arg)



Extracts the hour from a SAS time



HOUR("7:35:00"t) =7



value.

MINUTE(arg) Extracts the minutes from a SAS time

value.

SECOND(arg) Extracts the seconds from a SAS time



MINUTE("12:17:43 PM"t)

= 17

SECOND("2:17:43"t) = 43



value.



5.3 Creating Dates, Times, and Datetimes from Numbers or

Other Information



5.3.1 Introduction



This series of functions will create SAS date, time, and datetime values from

numerical variables or constants. While informats take complete date, time, and

datetime references and translate them to their corresponding SAS value, these

functions will create a SAS value from discrete pieces such as month, day, and year.



5.3.2 List of Functions and Their Descriptions

DATEJUL(Julian-date);



DATEJUL(Julian-date); creates a SAS date value from a numeric value representing a

Julian date. Julian-date must be of the type yy(yy)ddd, where yy(yy) is two or four

digits representing the year, and ddd must be a number from 1 to 365 (366 if a leap

year). If you use two digits for the year, the YEARCUTOFF= option will be used to

determine the century. The following table gives examples of how to apply this

function:

Formatted

SAS



with



Sample Function



Date



MMDDYY10.



Call



Value Format



Comments



OPTIONS







With the YEARCUTOFF value of



10/13/1921



YEARCUTOFF=1920; 13959



1920, the 21 is interpreted as



DATEJUL(21286)



1921.



OPTIONS



22566 10/13/2021



YEARCUTOFF=2000;



If YEARCUTOFF is 2000, the 21

is interpreted as 2021.



DATEJUL(21286)

DATEJUL(2014174)



19897 06/23/2014



DATEJUL(1989005)



10597 01/05/1989



DATEJUL(00368)



.



.



368 is not a valid value for a

Julian day, so the function

returns a missing value.



DHMS(date,hour,minute,second);



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

2 Extracting Pieces from SAS Date, Time, and Datetime Values

Tải bản đầy đủ ngay(0 tr)

×