data test;
input calendar_date DATETIME.;
cards;
2017/01/01 01:01:50
2017/01/02 05:06:30
;
run;
I tried with a lot of different formats for this. But always i am getting a missing data. Any help is appreciated. Thank you.
Read them separately and combine after the fact?
You
data test;
input calendar_date yymmdd10. calendar_time time.;
format calendar_date date9. calendar_time time. calendarDT datetime.;
calendarDT=dhms(calendar_date, 0, 0, calendar_time);
cards;
2017/01/01 01:01:50
2017/01/02 05:06:30
;
run;
proc print data=test;
run;
Or you can try ANYDTDTM. - note that this assumes that your date is yymmdd, but it could be yyddmm but that's extremely rare to se. The current date format is not what SAS would consider DATETIME.
data test;
input calendar_date anydtdtm.;
format calendar_date datetime.;
cards;
2017/01/01 01:01:50
2017/01/02 05:06:30
;
run;
proc print data=test;
run;
@yashk wrote:
data test;
input calendar_date DATETIME.;
cards;
2017/01/01 01:01:50
2017/01/02 05:06:30
;
run;
I tried with a lot of different formats for this. But always i am getting a missing data. Any help is appreciated. Thank you.
Great idea. Thank you. But i believe we cannot perform calculations if we combine variables. I tried below similar below but i was unable to perform calculations on the new variable.
data test;
input calendar_date yymmdd10. calendar_time time.;
Combined=catx(' ',put(calendar_date,yymmdd10.), put(calendar_time,time.));
cards;
2017/01/01 01:01:50
2017/01/02 05:06:30
;
run;
proc print data=test;
format calendar_Date yymmdd10. calendar_time time.;
run;
But i believe we cannot perform calculations if we combine variables
That's incorrect. You combined the variables together using CATX() - this creates a character variable, which you cannot perform numerical calculations.
I used the DHMS() function which returns a SAS datetime or a number which you can use for date/time calculations.
@yashk wrote:
Great idea. Thank you. But i believe we cannot perform calculations if we combine variables. I tried below similar below but i was unable to perform calculations on the new variable.
data test;
input calendar_date yymmdd10. calendar_time time.;
Combined=catx(' ',put(calendar_date,yymmdd10.), put(calendar_time,time.));
cards;
2017/01/01 01:01:50
2017/01/02 05:06:30
;run;
proc print data=test;
format calendar_Date yymmdd10. calendar_time time.;
run;
data test;
input calendar_date :anydtdtm.;
format calendar_date datetime20.;
cards;
2017/01/01 01:01:50
2017/01/02 05:06:30
;
run;
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.
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.