Prev: Scroll to a particular column in viewtable
Next: Why SAS programmers need to be aware of perl and R
From: mark on 2 Mar 2010 23:41 Hello , could you please guide me. I want to use the date-time format as "14JUL2009:08:49:26" in place of "14/07/2009:08:49:26". I have been given only the SAS datafile with no information on the width of the column variables.What should i use in the datastep.This is because I want to use the timepart() and datepart() functions which require time and date to be in this form. Kindly guide. regards mark
From: Sierra Information Services on 3 Mar 2010 00:50 The datetime format you use on the numeric datetime variable values stored in your data set has nothing to do with applying the DATEPART or TIMEPART functions, which work/operate on the numeric values of the variable itself. Remember, SAS stores dates and times as NUMBERS. A datetime variable stores the date _and_ the time in a single (large) number which is the number of seconds from midnight, January 1, 1960 to the date, and time on which the event your are studying occurred. A date variable is the number of days before or after Jan 1 1960 and a time variable is the number of seconds from midnight. A SAS Format changes how the values are "seen" or "displayed" in the output, they do NOT change the values themselves! Here is an example where I have created two datetime variables, formatted versions of them with variants of the DATETIME format, and then used the DATEPART and TIMEPART functions. I hope this helps you. Andrew Karp Sierra Information Services http://www.sierrainformation.com 2539 data _null_; 2540 a_date ='15jan2010:21:44:17'dt; 2541 b_date = '23feb2008:04:14:24'dt; 2542 a1_date = a_date; 2543 b1_date = b_date; 2544 format a1_date datetime. b1_date datetime32.; 2545 put a_date = a1_date=; 2546 put b_date = b1_date=; 2547 run; a_date=1579211057 a1_date=15JAN10:21:44:17 b_date=1519359264 b1_date=23FEB2008:04:14:24 NOTE: DATA statement used (Total process time): real time 0.11 seconds cpu time 0.00 seconds 2548 data _null_; 2549 a_date ='15jan2010:21:44:17'dt; 2550 b_date = '23feb2008:04:14:24'dt; 2551 a1_date = a_date; 2552 b1_date = b_date; 2553 datepart_a_date = datepart(a_date); 2554 datepart_a1_date= datepart(a1_date); 2555 timepart_b_date = timepart(b_date); 2556 timepart_b1_date = timepart(b1_date); 2557 format a1_date datetime. b1_date datetime32.; 2558 put a_date = a1_date=; 2559 put datepart_a_date= datepart_a1_date=; 2560 put b_date = b1_date=; 2561 put timepart_b_date= timepart_b1_date=; 2562 run; a_date=1579211057 a1_date=15JAN10:21:44:17 datepart_a_date=18277 datepart_a1_date=18277 b_date=1519359264 b1_date=23FEB2008:04:14:24 timepart_b_date=15264 timepart_b1_date=15264 NOTE: DATA statement used (Total process time): real time 0.46 seconds cpu time 0.03 seconds 2563 * format values returned by the datepart and timepart functions; 2564 data _null_; 2565 a_date ='15jan2010:21:44:17'dt; 2566 b_date = '23feb2008:04:14:24'dt; 2567 a1_date = a_date; 2568 b1_date = b_date; 2569 datepart_a_date = datepart(a_date); 2570 datepart_a1_date= datepart(a1_date); 2571 timepart_b_date = timepart(b_date); 2572 timepart_b1_date = timepart(b1_date); 2573 format a1_date datetime. b1_date datetime32.; 2574 put a_date = a1_date=; 2575 put datepart_a_date= datepart_a1_date=; 2576 put b_date = b1_date=; 2577 put timepart_b_date= timepart_b1_date=; 2578 format timepart_b_date timepart_b1_date time.; 2579 format datepart_a_date datepart_a1_date mmddyy10.; 2580 run; a_date=1579211057 a1_date=15JAN10:21:44:17 datepart_a_date=01/15/2010 datepart_a1_date=01/15/2010 b_date=1519359264 b1_date=23FEB2008:04:14:24 timepart_b_date=4:14:24 timepart_b1_date=4:14:24 NOTE: DATA statement used (Total process time): real time 0.06 seconds cpu time 0.00 seconds On Mar 2, 8:41�pm, mark <mark.chas...(a)yahoo.in> wrote: > Hello , > > could you please guide me. I want to use the date-time format as > "14JUL2009:08:49:26" in place of "14/07/2009:08:49:26". I have been > given only the SAS datafile with no information on the width of the > column variables.What should i use in the datastep.This is because I > want to use the timepart() and datepart() functions which require time > and date to be in this form. > > Kindly guide. > > regards > mark
|
Pages: 1 Prev: Scroll to a particular column in viewtable Next: Why SAS programmers need to be aware of perl and R |