BookmarkSubscribeRSS Feed
yashk
Fluorite | Level 6

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.

 

4 REPLIES 4
Reeza
Super User

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.

 


 

yashk
Fluorite | Level 6

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;

Reeza
Super User

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;


 

 

PeterClemmensen
Tourmaline | Level 20
data test;
input calendar_date :anydtdtm.;
format calendar_date datetime20.;
cards;
2017/01/01 01:01:50
2017/01/02 05:06:30
;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 7103 views
  • 2 likes
  • 3 in conversation