Enterprise Guide DHMS Date Time concatenation

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Enterprise Guide DHMS Date Time concatenation

Dear all,

 

I have a table (SAS EG) with date values (type date) and Time values (type String), and want to create dateTime-values from that.

 

Date example:

 

00012_Begindatum deze episode00013_Begintijd deze episodeBeginTimeHours_NumericBeginDateTime
3-11-20169:489:489.
2-5-201410:4510:4510.
30-9-201414:3514:3514.
30-9-201415:0015:0015.
1-10-201417:2517:2517

.

 

I used the following expression to create the (SAS EG) "Calculated Field":

 

DHMS(t1.v00012,inputn(SUBSTR(t1.v00013, 1, 2),'2.'),inputn(SUBSTR(t1.v00013, 3, 2),'2.'),0 )

 

but get "missing values". The Log file shows this:

 

24 PROC SQL;
25 CREATE TABLE WORK.'Argus with duration'n AS
26 SELECT t1.v00012,
27 t1.v00013,
28 /* BeginTime */
29 (input(t1.v00013,time5.)) FORMAT=HHMM5. LABEL="BeginTime" AS BeginTime,
30 /* Hours_Numeric */
31 (INPUTN(SUBSTR(t1.v00013, 1, 2),'2.')) AS Hours_Numeric,
32 /* BeginDateTime */
33 (DHMS(t1.v00012,inputn(SUBSTR(t1.v00013, 1, 2),'2.'),inputn(SUBSTR(t1.v00013, 3, 2),'2.'),0 ))
34 FORMAT=DATETIME13. LABEL="BeginDateTime" AS BeginDateTime
35 FROM WORK.'ARGUS WITH ADMISSION INFO'n t1;
NOTE: Invalid argument 1 to function INPUTN. Missing values may be generated.
NOTE: Invalid (or missing) arguments to the DHMS function have caused the function to return a missing value.
NOTE: Invalid time value
NOTE: Invalid argument to function INPUT. Missing values may be generated.
NOTE: Table WORK.'ARGUS WITH DURATION'n created, with 7585 rows and 5 columns.

36 QUIT;

 

Remark: Inputn function works for the HOURS_NUMERICvariable, and copied into the DHMS-funtion it raises these warnings.

 

Question: what do I do wrong?

 

Any help will be appreciated,

 

Regards, Hans Troost


Accepted Solutions
Solution
‎02-14-2017 06:42 AM
Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: Enterprise Guide DHMS Date Time concatenation

This works;

data want;
  d="3-11-2016"; t="9:48"; 
  date_time=dhms(input(d,ddmmyy10.),hour(input(t,time5.)),minute(input(t,time5.)),0);
  format date_time datetime.;
run;

You only need the date_time row.  Of course, this assumes your data is right, if there are invalid values then it will fail as with any logic.

View solution in original post


All Replies
Solution
‎02-14-2017 06:42 AM
Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: Enterprise Guide DHMS Date Time concatenation

This works;

data want;
  d="3-11-2016"; t="9:48"; 
  date_time=dhms(input(d,ddmmyy10.),hour(input(t,time5.)),minute(input(t,time5.)),0);
  format date_time datetime.;
run;

You only need the date_time row.  Of course, this assumes your data is right, if there are invalid values then it will fail as with any logic.

New Contributor
Posts: 3

Re: Enterprise Guide DHMS Date Time concatenation

Thanks RW9. Works fine for me. Hans
Super User
Posts: 1,228

Re: Enterprise Guide DHMS Date Time concatenation

v00013 is probably a numeric time variable, so it is wrong to use INPUT function.

You can define:

  hh = hour(v00013);  mm = minute(v00013);  ss = second(v00013);

then:

  DateTime = dhms(v00012,hh,mm,ss);

New Contributor
Posts: 3

Re: Enterprise Guide DHMS Date Time concatenation

Thanks Shmuel for your fast reply.

 

The TIME value is a string and not numeric. So I tried RW9's solution and that works fine for me.

 

Regards, Hans

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 98 views
  • 0 likes
  • 3 in conversation