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.
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. ;
...
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.