Desktop productivity for business analysts and programmers

Need to convert character mm/dd/yyyy to SAS date and time in Query Builder

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

Need to convert character mm/dd/yyyy to SAS date and time in Query Builder

[ Edited ]

Can this be done in the advanced expression calculation?

 

Example data to convert from char to SAS date:

 

02/12/2016 to 12FEB2016:00:00:00

 

 

 

 


Accepted Solutions
Solution
‎07-06-2016 09:49 AM
Super User
Super User
Posts: 6,848

Re: Need to convert character mm/dd/yyyy to SAS date and time

[ Edited ]

Will that tool let you type an actualy function?  If your variable with the characters in is named CHARVAR then this assignment statement will make the variable DATETIME have the equivalent datetime value.

datetime=dhms(input(charvar,'MMDDYY10.'),,,0);

View solution in original post


All Replies
Solution
‎07-06-2016 09:49 AM
Super User
Super User
Posts: 6,848

Re: Need to convert character mm/dd/yyyy to SAS date and time

[ Edited ]

Will that tool let you type an actualy function?  If your variable with the characters in is named CHARVAR then this assignment statement will make the variable DATETIME have the equivalent datetime value.

datetime=dhms(input(charvar,'MMDDYY10.'),,,0);
Community Manager
Posts: 2,889

Re: Need to convert character mm/dd/yyyy to SAS date and time in Query Builder

[ Edited ]

Yes, @Tom is correct.  The Advanced Expression window allows this:

 

dhms(input(t1.charvar,'MMDDYY10.'),,,0)

 

Looks like this in your window:

 

ae.png

 

Super User
Posts: 19,167

Re: Need to convert character mm/dd/yyyy to SAS date and time in Query Builder

@ChrisHemedinger Are the quotes required around the format? I think it might be like the following:

 

dhms(input(t1.charvar, MMDDYY10.),,,0)

 

 

Super User
Super User
Posts: 6,848

Re: Need to convert character mm/dd/yyyy to SAS date and time in Query Builder

With the INPUT() functions you do not want the quotes around the format since the second argument is a format.

But the INPUTN() function , or the INPUTC() function, take an expression for the second argument so you do need the quotes.

Contributor
Posts: 41

Re: Need to convert character mm/dd/yyyy to SAS date and time in Query Builder

This worked.  I had to add DATETIME20 to the format under "Modify additional options" in Enterprise Guide.

 

Thanks all!

 

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 2797 views
  • 0 likes
  • 4 in conversation