Desktop productivity for business analysts and programmers

DateTime Issue

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 104
Accepted Solution

DateTime Issue

Hi,

I have issues with these datetime variables.  They contain extra micro seconds.  Because of that I cannot do sum or count based on month/year or use TimeStamp prompt.

Please see the image below for what I meant.  See the last 3 numbers after the seconds.  I want to get rid of those last 4 numbers.

Capture.PNG

Thanks in advance.


Accepted Solutions
Solution
‎06-05-2015 04:21 PM
Grand Advisor
Posts: 10,235

Re: DateTime Issue

No manipulation of the value needed for many types of summaries. Assign an appropriated format, such as DTMONYY;

Proc means data=have;

     class IssueDate;

     var < a list of variables to summarize>;

     format IssueDate ddmonyy7.;

run;

The formatted values will be used by most procedures to group values.

View solution in original post


All Replies
Super User
Posts: 1,117

Re: DateTime Issue

Please try to use the informat datetime22. to read and display the datetime as expected

data have;

input x : datetime22.;

format x datetime20.;

cards;

02dec2014:18:05:32.037

;

run;

else, simply try to use the format datetime20. to get the expected display.

Thanks,

Jag

Thanks,
Jag
Super User
Super User
Posts: 6,367

Re: DateTime Issue

Datetime values are the number of seconds since 1/1/1960.  If you do not want the fractional parts of a second then use ROUND() or INT() function to convert the value to an integer.

Respected Advisor
Posts: 4,609

Re: DateTime Issue

I'm always trying to manipulate date and datetime data in ways that are independent of internal representation. I'm not certain it can always be done but in this case you could use a time constant representing a single second (whatever its value for SAS) in the ROUND function :

data have;

input x : datetime22.;

y = round(x, '00:00:01't);

format x y datetime22.3;

datalines;

02dec2014:18:05:32.037

;

proc print; run;

PG

PG
Esteemed Advisor
Posts: 6,698

Re: DateTime Issue

Like that, as it will work even when SAS changes the datetime representation to nanoseconds since the Big Bang.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
‎06-05-2015 04:21 PM
Grand Advisor
Posts: 10,235

Re: DateTime Issue

No manipulation of the value needed for many types of summaries. Assign an appropriated format, such as DTMONYY;

Proc means data=have;

     class IssueDate;

     var < a list of variables to summarize>;

     format IssueDate ddmonyy7.;

run;

The formatted values will be used by most procedures to group values.

Frequent Contributor
Posts: 104

Re: DateTime Issue

Thank you solved my problem.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 572 views
  • 8 likes
  • 6 in conversation