09NOV2020 is usually DATE9, but I'm not sure where to put this here. Ideally, I'm trying to convert from DATE9. to MMDDYYD10.
data test
dt1: "09NOV2020" ;
dt2: input(dt1, MMDDYYD10.);
format dt2 MMDDYYD10.;
run;
Your example code is a little off. Assignment statements use = , not : .
There is no informat named DDMMYYD. There is one named DDMMYY that will read strings in the style produced by the MMDDYYD format. But your strings are not in that style. They are in the style that the DATE informat can read.
data test ;
dt1 = "09NOV2020" ;
dt2 = input(dt1, date9.);
format dt2 MMDDYYD10.;
put dt1= dt2=;
run;
802 data test ; 803 dt1 = "09NOV2020" ; 804 dt2 = input(dt1, date9.); 805 format dt2 MMDDYYD10.; 806 put dt1= dt2=; 807 run; dt1=09NOV2020 dt2=11-09-2020 NOTE: The data set WORK.TEST has 1 observations and 2 variables.
PS: Why would you want to display dates in MDY order? That will confuse half of your audience. If you don't want to use DATE format with your new date variable then use YYMMDD format and then no one will confuse December tenth for the twelfth of October.
So you can't convert a string 09NOV2020 to 09-09-2020, but you can convert it to either 09-11-2020 or 11-09-2020 (whichever you prefer)
data test;
dt1= "09NOV2020" ;
dt2= input(dt1, date9.);
format dt2 mmddyyd10.;
run;
That gives you 11-09-2020. If you want 09-11-2020, its an obvious modification to the above code.
TEST was the name of the dataset that the example test program program was creating to show you how to transform a string into a date. It did not read in any existing data instead it just hardcoded the example string value.
In general it is better to create a new dataset with the changes. If you try to modify your existing dataset and make a mistake you might lose data.
So if your existing "sheet" has been converted into a SAS dataset named HAVE then you can use a data step like this to create a new dataset named WANT.
data want;
set have;
....
run;
Replace the ... with the SAS data step statements todo the calculations you want. Like these statements :
dt2 = input(dt1, date9.);
format dt2 MMDDYYD10.;
Your example code is a little off. Assignment statements use = , not : .
There is no informat named DDMMYYD. There is one named DDMMYY that will read strings in the style produced by the MMDDYYD format. But your strings are not in that style. They are in the style that the DATE informat can read.
data test ;
dt1 = "09NOV2020" ;
dt2 = input(dt1, date9.);
format dt2 MMDDYYD10.;
put dt1= dt2=;
run;
802 data test ; 803 dt1 = "09NOV2020" ; 804 dt2 = input(dt1, date9.); 805 format dt2 MMDDYYD10.; 806 put dt1= dt2=; 807 run; dt1=09NOV2020 dt2=11-09-2020 NOTE: The data set WORK.TEST has 1 observations and 2 variables.
PS: Why would you want to display dates in MDY order? That will confuse half of your audience. If you don't want to use DATE format with your new date variable then use YYMMDD format and then no one will confuse December tenth for the twelfth of October.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.