Help using Base SAS procedures

Global macro to format dates

Posts: 59

Global macro to format dates

I imported a spreadsheet into sas.  I ran some queries against the import and it is ready for distribution.  The dates are in date9 format.  Is there a global macro that I can plug in to do an auto change to mmddyy10.

I could export it, then import again and define the dates, however there are about 30 columns with dates.

Super User
Super User
Posts: 8,089

Re: Global macro to format dates

Posted in reply to omega1983

To change the way that a variable is displayed you just need to use a FORMAT statement.

In your case it would be in the form:

FORMAT var1 var2 ..... MMDDYY10. ;

If you add it to a data step then the formats are permanently attached, or you could just use it in the report step where you want to use a different display format.

You can automate the generation of the list of variable names by querying the metadata.

proc sql noprint;

select name into :datevars separated by ' '

from dictionary.columns

  where libname='MYLIB' and memname='MYDATA'

     and format = 'DATE'




format &datevars MMDDYY10. ;


Super User
Posts: 23,700

Re: Global macro to format dates

Posted in reply to omega1983

Note that the comparisons in the where clause are case sensitive.

proc sql;

select var_date into :var_dates separated by  " "

from sashelp.vtable

where libname="SASHELP" and memname="STOCKS" and format="DATE9." ;


data want;

set have;

format &var_dates mmddyy10.;


Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation