14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

112 Types of Data Chapter 6<br />

Date-Time Functions and Formats<br />

3388649872<br />

Short Date(Today());<br />

"05/19/2011"<br />

Long Date(Today());<br />

"Thursday, May 19, 2011"<br />

Abbrev Date(Today());<br />

"5/19/2011"<br />

MDYHMS(Today());<br />

"05/19/2011 11:37:52 AM"<br />

The date argument in parentheses can be seconds (or any function that returns seconds), or any date-time<br />

literal value. For example, both of the following expressions return the same value:<br />

Long Date(3388649872);<br />

Long Date(19May2011);<br />

"Thursday, May 19, 2011"<br />

Note: Long Date() and Abbrev Date() values are formatted according to your computer’s regional<br />

settings.<br />

Extract Parts of Dates<br />

You can extract parts of date values using the functions Month(), Day(), Year(), Day Of Week(), Day<br />

Of Year(), Week Of Year(), Time Of Day, Hour(), Minute(), and Second(), which all return<br />

integers. If today is March 24th, 2011, each of the following examples returns the 144th day of the year:<br />

Day of Year(Today());<br />

Day of Year(24May2011);<br />

Day of Year(Date MDY(5,24,2011));<br />

144<br />

Example<br />

A data table column named Date contains date-time values that are formatted as "m/d/y". You want to<br />

create a column that shows only the time. In the following script, the second column’s formula extracts the<br />

time of day from the Date value in the first column.<br />

New Table( "Assembly Tests",<br />

Add Rows( 1 ),<br />

New Column( "Date",<br />

Numeric, Continuous,<br />

Format( "m/d/y" ),<br />

Set Values( [3389083557] )<br />

),<br />

New Column( "Time",<br />

Numeric, Continuous,<br />

Formula(Format(Time Of Day( :Date ), "h:m:s"))<br />

)<br />

);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!