BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robm
Quartz | Level 8

 

 

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.

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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

3 REPLIES 3
ballardw
Super User

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.

FreelanceReinh
Jade | Level 19

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.

 

robm
Quartz | Level 8

yeah! that worked perfectly thanks!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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