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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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