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!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.