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?
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: