BookmarkSubscribeRSS Feed
SAS93
Quartz | Level 8

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? 

1 REPLY 1
Reeza
Super User

@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? 


 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 771 views
  • 2 likes
  • 2 in conversation