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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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