How do I change the dates
9/2001
11/2000
1/2011
to
9/15/2001
11/15/2000
1/15/2011 ?
There are many more dates in format mm/yyyy and I want to change them to mm/15/yyyy.
data _null_;
month_string = '9/2001';
SAS_Date = mdy(input(scan(month_string,1),2.),15,input(scan(month_string,2),4.));
format SAS_Date mmddyys10.;
put _all_;
run;
data _null_;
month_string = '9/2001';
SAS_Date = mdy(input(scan(month_string,1),2.),15,input(scan(month_string,2),4.));
format SAS_Date mmddyys10.;
put _all_;
run;
Thank You.
Just prefix the string with 15/ and use the DDMMYY informat.
data have;
input string $10.;
cards;
9/2001
11/2000
1/2011
;
data want;
set have;
date=input(cats('15/',string),ddmmyy10.);
format date yymmdd10.;
run;
proc print;
run;
Obs string date 1 9/2001 2001-09-15 2 11/2000 2000-11-15 3 1/2011 2011-01-15
PS Display dates in DMY or MDY order will confuse 50% of your audience. Use YMD order or the DATE format.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.