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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1348 views
  • 8 likes
  • 6 in conversation