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.
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,
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.
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.
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,
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.
yeah! that worked perfectly thanks!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.