Sample 24591: Convert a character variable that represents a date into a SASĀ® date
The sample code on the Full Code tab illustrates how to use the INPUT function to convert a character value that represents a date into a SAS date value.
Also, for more information about date functions, see the following SAS tutorial video:
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
data one;
input chardate1 :$6. chardate2 :$9. chardate3 $10. chardate4 :$9.;
datalines;
010199 31dec1999 21/09/2005 5/9/2005
;
/* Use the INPUT function to convert a character value that represents a date */
/* into a SAS date value. Choose the second parameter to the INPUT function */
/* based upon what the current character value looks like. Use a FORMAT */
/* statement to apply the date format you want when you are done. */
/* */
data two;
set one;
sasdate1=input(chardate1,mmddyy6.);
sasdate2=input(chardate2,date9.);
sasdate3=input(chardate3,ddmmyy10.);
sasdate4=input(chardate4,ddmmyy10.);
format sasdate1 mmddyy10. sasdate2 yymmdd10. sasdate3 date9. sasdate4 monyy7. ;
run;
proc print;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.