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? 


 

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
  • 1 reply
  • 311 views
  • 2 likes
  • 2 in conversation