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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.