Desktop productivity for business analysts and programmers

How to concatenate string and declare as date constant

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

How to concatenate string and declare as date constant

Is this possible to do in Enterprise Guide filter?   I usually do a date compare in a filter like this that works fine:

 

datepart(exit_date) >= '15Aug2017'd

 

However I would like the to set it up so the year is dynamic, something like:

 

'15Aug' || PUT(YEAR(Date()-181), 4.)

 

This code produces the correct character format I want 15Aug2017, but I can't just put a 'd' at the end to assign it as date constant for comparison.   Any suggestions would be much appreciated.  Thanks, Kenny.

 

EG 6.1

SAS 9.4


Accepted Solutions
Solution
‎08-16-2017 09:25 AM
Super User
Posts: 8,055

Re: How to concatenate string and declare as date constant

Use the input() function to convert the string to a date:

datepart(exit_date) >= input('15Aug' || PUT(YEAR(Date()-181), 4.),date9.)

Or use the intnx() function to do date calculations:

datepart(exit_date) >= intnx('year','15Aug2017'd,-181,'s');
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎08-16-2017 09:25 AM
Super User
Posts: 8,055

Re: How to concatenate string and declare as date constant

Use the input() function to convert the string to a date:

datepart(exit_date) >= input('15Aug' || PUT(YEAR(Date()-181), 4.),date9.)

Or use the intnx() function to do date calculations:

datepart(exit_date) >= intnx('year','15Aug2017'd,-181,'s');
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 2

Re: How to concatenate string and declare as date constant

Posted in reply to KurtBremser

Thanks!  That works perfectly.

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 137 views
  • 0 likes
  • 2 in conversation