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!
HoHo. You are luck you have SAS.
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;
Notes (7)
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
1 | 2014-03-17 16:58:39.512986+0000 | 03-17 16:58 |
---|
Hi,
If its just character you want (and should still sort correctly:
new_var=substr(dt,6,11);
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.
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.