BookmarkSubscribeRSS Feed
Crubal
Quartz | Level 8

Hi,

I have a question about SAS basic procedure, how to convert time like "2014-03-17 16:58:39.512986+0000" to a time only with day(month), hour and minute. Like "03-17 16:58"

Thanks so much!

2 REPLIES 2
Ksharp
Super User

HoHo. You are luck you have SAS.

Code: Program

proc format;
picture fmt
other='%0m-%0d %0H:%0M'(datatype=datetime);
run;
data x;
a="2014-03-17 16:58:39.512986+0000";
b=input(scan(a,1,'.'),anydtdtm24.);
format b fmt12.;
run;
proc print;run;


Log: Program

Notes (7)

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

53 

54 proc format;

55 picture fmt

56 other='%0m-%0d %0H:%0M'(datatype=datetime);

NOTE: Format FMT is already on the library WORK.FORMATS.

NOTE: Format FMT has been output.

57 run;

NOTE: PROCEDURE FORMAT used (Total process time):

  real time 0.02 seconds

  cpu time 0.01 seconds

  

58 data x;

59 a="2014-03-17 16:58:39.512986+0000";

60 b=input(scan(a,1,'.'),anydtdtm24.);

61 format b fmt12.;

62 run;

NOTE: The data set WORK.X has 1 observations and 2 variables.

NOTE: DATA statement used (Total process time):

  real time 0.00 seconds

  cpu time 0.00 seconds

  

63 proc print;run;

NOTE: There were 1 observations read from the data set WORK.X.

NOTE: PROCEDURE PRINT used (Total process time):

  real time 0.03 seconds

  cpu time 0.02 seconds

  

64 

65 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

75 


Results: Program

12014-03-17 16:58:39.512986+000003-17 16:58

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

If its just character you want (and should still sort correctly:

new_var=substr(dt,6,11);

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 886 views
  • 6 likes
  • 3 in conversation