data test(keep=mydate);
set test2;
run;
sample data
mydate
17JAN2017:18:36:00.000000
I wish to display mydate as
01/17/2017 :18:36:00.000000
I tried using mmddyy10 hh:mm:ss and get syntax error. By default it displays in date9 plus the hr min sec interval. Just want to display as mmddyy format as above in bold
Try next code:
data _NULL_;
timestamp = '17JAN2017:18:36:00'dt;
format timestamp datetime26.;
put timestamp=;
run;
I don't think that's what the op wants. In particular, it seems they want this format:
mm/dd/yyyy :hh:mm:ss.ffffff
You can get close to this by making a custom format via the PICTURE statement in proc format. It has the "datatype=datetime" option, which tells it to obey datetime-related directives (the % signed elements below):
proc format;
picture mydtfmt low-high='%Y%0m%0d %0H:%0M:%0S' (datatype=datetime) ;
run;
data _null_;
dt="17jan2017:18:36:00.300000"dt;
put dt=mydtfmt26.6;
run;
Unfortunately, this generates a value with no decimals (because there are no datetime directives for fractions of a second):
dt=20170117 18:36:00
So you have to make a text variable using the mydtfmt format above concatenated with the fractional component, as in:
proc format;
picture mydtfmt
low-high='%Y%0m%0d %0H:%0M:%0S' (datatype=datetime) ;
run;
data _null_;
dt="17jan2017:18:36:00.300000"dt;
fraction=substr(cats(mod(dt,1),'000000'),2,7) ;
date_text=put(dt,mydtfmt20.)||fraction;
put date_text=;
/** or more compactly (without intermediate variable "fraction" .... **/
date_text2=put(dt,mydtfmt20.)||substr(cats(mod(dt,1),'000000'),2,7);
put date_text2=;
run;
You can do this (sort of) with a picture format:
proc format;
picture myDt
other = '%0m/%0d/%Y:%0H:%0M:%0S.000000' (datatype=datetime);
run;
data _NULL_;
timestamp = '17JAN2017:18:36:05'dt;
put timestamp = myDt26.;
run;
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.