I have 2 numeric variables for day and month respectively: DD_LV and MM_LV. I also have a general YY_ variable for year.
I know I have to turn them into character variables first, but I ultimately want to concatenate them into a single MM/DD/YY date variable.
What's the most efficient way to approach this?
@SAS93 wrote:
I know I have to turn them into character variables first, but I ultimately want to concatenate them into a single MM/DD/YY date variable.
No, you do not have to turn them into character variables.
data want_date;
mm_lv=10;
dd_lv=14;
yy_variable = 2020;
date_var_num = mdy(mm_lv, dd_lv, yy_variable);
format date_var_num mmddyy10.;
date_var_char8 = put(date_var_num, mmddyys8.);
date_var_char10 = put(date_var_num, mmddyys10.);
run;
proc print;
run;
Results:
Obs mm_lv dd_lv yy_variable date_var_num date_var_char8 date_var_char10 1 10 14 2020 10/14/2020 10/14/20 10/14/2020
@SAS93 wrote:
I have 2 numeric variables for day and month respectively: DD_LV and MM_LV. I also have a general YY_ variable for year.
I know I have to turn them into character variables first, but I ultimately want to concatenate them into a single MM/DD/YY date variable.
What's the most efficient way to approach this?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.