BookmarkSubscribeRSS Feed
omega1983
Calcite | Level 5

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.

2 REPLIES 2
Tom
Super User Tom
Super User

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'

;

quit;

...

format &datevars MMDDYY10. ;

...

Reeza
Super User

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." ;

quit;

data want;

set have;

format &var_dates mmddyy10.;

run;

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1444 views
  • 6 likes
  • 3 in conversation