DATA Step, Macro, Functions and more

how to read Timestamp format of YYYY/MM/DD HH:MM:SS

Reply
Occasional Contributor
Posts: 6

how to read Timestamp format of YYYY/MM/DD HH:MM:SS

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.

 

Super User
Posts: 23,224

Re: how to read Timestamp format of YYYY/MM/DD HH:MM:SS

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.

 


 

Occasional Contributor
Posts: 6

Re: how to read Timestamp format of YYYY/MM/DD HH:MM:SS

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;

Super User
Posts: 23,224

Re: how to read Timestamp format of YYYY/MM/DD HH:MM:SS

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;


 

 

PROC Star
Posts: 1,209

Re: how to read Timestamp format of YYYY/MM/DD HH:MM:SS

data test;
input calendar_date :anydtdtm.;
format calendar_date datetime20.;
cards;
2017/01/01 01:01:50
2017/01/02 05:06:30
;
run;
Ask a Question
Discussion stats
  • 4 replies
  • 449 views
  • 2 likes
  • 3 in conversation