biscuit
biscuit

Reputation: 11

Changing date format in SAS9.3

Does anyone know how to change a date variable from Date9 to MMDDYY10 format in SAS9.3? I've tried using the put and input functions, but the result is null

Upvotes: 1

Views: 26756

Answers (3)

vasja
vasja

Reputation: 4792

For changing the format of variable in a table - PROC SQL or PROC DATASETS:

data WORK.TABLE1;
    format DATE1 DATE2 date9.;
    DATE1 = today();
    DATE2 = DATE1;
run;

proc contents;
run;

proc datasets lib=WORK nodetails nolist;
modify TABLE1;
    format DATE1 mmddyy10.;
quit;

proc sql;
alter table WORK.TABLE1
    modify DATE2 format=mmddyy10.
;
quit;

proc contents;
run;

Upvotes: 0

DomPazz
DomPazz

Reputation: 12465

Formats are nothing but instructions on how to display a value. Dates are numeric represented as the number of days from 1JAN1960.

data x;
format formated1 date9. formated2 mmddyy10.;
noformated = "01JAN1960"d;
formated1 = noformated;
formated2 = noformated;
run;

proc print data=x;
run;

Obs    formated1     formated2    noformated
1     01JAN1960    01/01/1960         0

In short, just change the format on the dataset and the date will be displayed with the new format.

Upvotes: 2

Neil Neyman
Neil Neyman

Reputation: 2158

Try both functions:

tmpdate = put(olddate,DATE9.);
newdate = input(tmpdate,MMDDYY10.);

Or maybe even

newdate = input(put(olddate,DATE9.),MMDDYY10.);

Upvotes: 0

Related Questions