DATA Step, Macro, Functions and more

converting DTWKDATX29. to a worddate18.

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 77
Accepted Solution

converting DTWKDATX29. to a worddate18.

 

 

I have a data filed that is DTWKDATX29. what I need to do is this 

 

proc sql noprint;
select max(put("As Of Date"n),worddate18.) into :aofd from robm.STCD110a;
quit;

 

get the max value into aofd how do I convert a  DTWKDATX29. to a  worddate18.


Accepted Solutions
Solution
‎03-14-2016 09:50 AM
Trusted Advisor
Posts: 1,115

Re: converting DTWKDATX29. to a worddate18.

[ Edited ]

Hi @robm,

 

The expression 

max(put("As Of Date"n),worddate18.)

is syntactically incorrect (both closing parentheses should be at the end). Also, please note that with max(put(...)) you would select the "largest" formatted value, i.e. the alphabetically last value. Using this sort order together with the WORDDATE18. format, 'September 30, 2016' would be the "maximum" date of 2016 (and '       May 1, 2016' the "minimum," due to right-alignment).

 

Therefore, I think you should use the following code:

proc sql noprint;
select put(datepart(max("As Of Date"n)),worddate18.) into :aofd trimmed
from robm.STCD110a;
quit;

That is, 

  1. select the latest among the non-missing datetime values
  2. extract the date part from this datetime value
  3. apply the WORDDATE18. format to the resulting date value
  4. trim leading (and trailing) blanks from the formatted value before it is written to macro variable AOFD

This assumes that "As Of Date"n is a numeric variable containing SAS datetime values and that you need a text such as 'January 5, 2016' in macro variable AOFD. A datetime format (like DTWKDATX29.) that may be associated with "As Of Date"n is irrelevant here.

 

View solution in original post


All Replies
Super User
Posts: 10,516

Re: converting DTWKDATX29. to a worddate18.

DTWKDATX means the valueis a datetime. So you want to extract the date portion using datepart(variablename) and then put that value or assign the format to a resulting variable.

Solution
‎03-14-2016 09:50 AM
Trusted Advisor
Posts: 1,115

Re: converting DTWKDATX29. to a worddate18.

[ Edited ]

Hi @robm,

 

The expression 

max(put("As Of Date"n),worddate18.)

is syntactically incorrect (both closing parentheses should be at the end). Also, please note that with max(put(...)) you would select the "largest" formatted value, i.e. the alphabetically last value. Using this sort order together with the WORDDATE18. format, 'September 30, 2016' would be the "maximum" date of 2016 (and '       May 1, 2016' the "minimum," due to right-alignment).

 

Therefore, I think you should use the following code:

proc sql noprint;
select put(datepart(max("As Of Date"n)),worddate18.) into :aofd trimmed
from robm.STCD110a;
quit;

That is, 

  1. select the latest among the non-missing datetime values
  2. extract the date part from this datetime value
  3. apply the WORDDATE18. format to the resulting date value
  4. trim leading (and trailing) blanks from the formatted value before it is written to macro variable AOFD

This assumes that "As Of Date"n is a numeric variable containing SAS datetime values and that you need a text such as 'January 5, 2016' in macro variable AOFD. A datetime format (like DTWKDATX29.) that may be associated with "As Of Date"n is irrelevant here.

 

Frequent Contributor
Posts: 77

Re: converting DTWKDATX29. to a worddate18.

yeah! that worked perfectly thanks!

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 254 views
  • 0 likes
  • 3 in conversation