BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sdang
Quartz | Level 8

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

6 REPLIES 6
Jagadishkatam
Amethyst | Level 16

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
Tom
Super User Tom
Super User

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.

PGStats
Opal | Level 21

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
ballardw
Super User

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.

sdang
Quartz | Level 8

Thank you solved my problem.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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