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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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