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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.