Hi,
How to get YYYY-MM-DDThh:mm:ss from date (yymmdd10.) and time ( tod8.)
My approch is mentioned below which is not proper for 1st record.
data xyz;
date="12-Aug-2020";
output;
Time= "11:45 PM";
output;
run;
data abc;
set xyz;
date1=put(input(date,anydtdte20.),yymmdd10.);
time1 = put(input(time,time8.),tod8.);
date_time = catx ("T",date1,time1);
run;
Thank you.
In SAS, YOU DO NOT STORE DATES OR TIMES AS CHARACTER.
Any format for display can be used whenever needed (eg for reports or export), but storing such values as character deprives you of the use of date&time functions and formats and necessitates re-conversion whenever a calculation needs to be done.
On top of that all, you need much more space to store a datetime as character (19 characters here) vs. numeric (only 8 bytes). Same for dates (minimum 8 characters without delimiters), which need only 4 numeric bytes.
Storing dates and times as character is plain dumb, to be VERY polite.
First of all, look at your dataset xyz; it has one observation with a missing time, and another with date and time.
Remove the OUTPUT statements if you want to have exactly one observation.
The proper way to create a timestamp (datetime) out of a separate time and date is the DHMS function:
data abc;
set xyz;
date1=input(date,anydtdte20.);
time1 = input(time,time8.);
date_time = dhms(date1,0,0,time1);
format date_time e8601dt19.;
run;
In SAS, YOU DO NOT STORE DATES OR TIMES AS CHARACTER.
Any format for display can be used whenever needed (eg for reports or export), but storing such values as character deprives you of the use of date&time functions and formats and necessitates re-conversion whenever a calculation needs to be done.
On top of that all, you need much more space to store a datetime as character (19 characters here) vs. numeric (only 8 bytes). Same for dates (minimum 8 characters without delimiters), which need only 4 numeric bytes.
Storing dates and times as character is plain dumb, to be VERY polite.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: