Hi SAS Community,
I am trying to solve this issue with date formatting. I just want to make the Enddate variable in a date format. I tried anydtdte and worddate. But all those end up with an error that the format doesnot exist.
data abcd ;
set abc ;
Informat Enddate : anydtdte20.;
run;
Code Enddate
A4466 | December 31, 2016 |
A7011 | December 31, 2015 |
A7042 | December 31, 2014 |
A7043 | December 31, 2014 |
A9544 | December 31, 2016 |
A9545 | December 31, 2016 |
B9000 | December 31, 2016 |
C1204 | December 31, 2013 |
C1300 | December 31, 2014 |
C1879 | June 30, 2013 |
Any help much appreciated.
If you are working from an existing character variable, instead of a reading from a source text file, then you will want to use the INPUT() function instead of the INPUT statement. You will need to create a new numeric variable to store the date as you cannot store it back into the character variable.
data abcd ;
set abc ;
datevar=input(Enddate,anydtdte20.);
format datevar date9.;
run;
You can't change the type of a variable, you have to use the correct informat when reading data.
data have;
input Code $5. @7 Enddate anydtdte20.;
format Enddate date9.;
datalines;
A4466 December 31, 2016
A7011 December 31, 2015
A7042 December 31, 2014
A7043 December 31, 2014
A9544 December 31, 2016
A9545 December 31, 2016
B9000 December 31, 2016
C1204 December 31, 2013
C1300 December 31, 2014
C1879 June 30, 2013
;
run;
Hello Andreas. This is the log i get when SAS is run. The End date is in $31 format if it helps for the soulution.
data abcd ;
118 set abc ;
119 input Code $5. @7 Enddate anydtdte20.;
-----------
48
ERROR 48-59: The informat $ANYDTDTE was not found or could not be loaded.
120 format Enddate date9.;
------
ERROR 48-59: The format $DATE was not found or could not be loaded.
121 run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.ABCD may be incomplete. When this step was stopped there were 0
observations and 2 variables.
WARNING: Data set WORK.ABCD was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
If you are working from an existing character variable, instead of a reading from a source text file, then you will want to use the INPUT() function instead of the INPUT statement. You will need to create a new numeric variable to store the date as you cannot store it back into the character variable.
data abcd ;
set abc ;
datevar=input(Enddate,anydtdte20.);
format datevar date9.;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.