AFHood Group Blog The thoughtless yammerings of marketing junkies..


SAS date format to YYYYMMDD

One of our many frustrations in life are date values in and out of SAS. Unless you are fortunate enough to be working on projects with standardized dates across the enterprise, you too will run into problems with dates in SAS.

In a large portion of industries, the YYYYMMDD format has become quite popular. It is wonderful in the IT and programming world. We all know you can sort (as in character sort) by this format and get a logical order. So here is a macro to help.

%macro yyyymmdd(DATEVAR) ;
Program Name :
Purpose      : formats dates into yyyymmdd format
Author       : hooda (
Arguments :

DateVar - SAS date variable

Change History

2009.02.02 - hooda - Macro created



/*------ END: AUTOLIB(YYYYMMDD) ----------------*/
%mend ;

Here is an example of how to use this macro.

data test;

Now I know what you are thinking.. "You wrote a macro for that?" And the answer is YES. As a group, I find that we use this function excessively. It's just easier for adhoc coding to have it available as a macro. It is effortless to remember "%yyyymmdd()" versus "COMPRESS(PUT(variable,YYMMDD10.),'-');".

I apologize if you think that one is silly, but it has been a favorite among our adhoc coders for years.

Comments (7) Trackbacks (0)
  1. This macro save my day!
    Thanks for sharing :)

  2. Thanks a lot!! This is AWESOME!! :)

  3. Thanks for sharing this. It solves frequent headaches.

  4. this is exactly what i want, really helpful!
    thanks a bunch!

  5. Thanks. This is very helpful.

  6. This is very helpful code…thankx :)

  7. Thx it helps

Leave a comment

No trackbacks yet.