Freaky_foxx
Freaky_foxx

Reputation: 43

How to convert dd-mmm-yyyy to date9 in sas

Want to convert date = 01-SEP-2021 to date = 01SEP2021. I used this code to convert:

New date = input(compress(date,'-'),date9.);

But that didn't work. I also used substring to remove the parts of day month and year but seems this method is a bit lengthy.

Upvotes: 0

Views: 4167

Answers (1)

Stu Sztukowski
Stu Sztukowski

Reputation: 12944

If the type is numeric and SAS already displays it as a date then it's a formatting issue.

proc datasets lib=work nolist;
    modify have;
        format date date9.;
quit;

Otherwise, it must be a character and you have to convert it to a date and display it in date9. format.

data want;
    date     = '01-SEP-2021';
    new_date = input(date, anydtdte.); *anydtdte. automatically reads a variety of date formats;
    
    format new_date date9.;
run;

Upvotes: 1

Related Questions