Help using Base SAS procedures

How to simplify date&time

Reply
Frequent Contributor
Posts: 118

How to simplify date&time

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!

Super User
Posts: 10,023

Re: How to simplify date&time

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

Super User
Super User
Posts: 7,949

Re: How to simplify date&time

Hi,

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

new_var=substr(dt,6,11);

Ask a Question
Discussion stats
  • 2 replies
  • 342 views
  • 6 likes
  • 3 in conversation