Posts

Showing posts with the label character conversions

How to convert numeric date values into character and from character date values into numeric using DATASTEP, PROC SQL and ARRAYS

1) Converting character date values into numeric: /*I) Using the DATASTEP:*/ 1) Data dates; input cdate $9.; cards; 16-apr-07 01-01-07 02-jun-07 13-sep-07 ; run; Data Convert; set dates; Date = input ( cdate , ANYDTDTE9.); format date date7.; run; 2) Data dates ; input cdate $9.; cards; 16-apr-2007 01-01-2007 02-jun-2007 13-sep-2007 ; run; Data Convert ; set dates; Date = input ( cdate , ANYDTDTE11.); format date date9.; run ; *II) Using Proc SQL; *Numeric date variable can be converted to character date variable by using the PUT function within PROC SQL.; proc sql; create table date_char as select PUT(date, date9.) as ndate from date_num; quit; *Character date variable can be converted to numeric date variable by using the INPUT function within PROC SQL.; Proc sql; create table date_num as select INPUT (date, mmddyy10.) as ndate format= mmddyy10. from date_char; quit ; Or Proc sql ; create table date_num as sel...