Q:

Is there a way to create a global macro that runs data from a proc sql through a regularly used equation? 

So effectively what I was wanting to do was the take sql date A and put it through a short equation that makes it spit out the number I need. 
I have code that will pull information from multiple different tables in different areas.   This information has dates that, some pull in oracle format from older tables, some in sas format, some in numeric datekeys with and are stored in the table as a number.   Now I am manipulating all the dates to a numeric datekey format of YYYYMMDD primarily because the majority of the dates in the tables are stored as numeric datekeys like that already.   That said I generally will pull dates that are actually in the tables as a date like such:
year(datepart(a.dt))*10000+month(datepart(a.dt))*100+day(a.dt)) as blahdt

In the middle of the proc sql.   This all works just fine, however I was wondering if there was a small macro I could write at the very beginning of the code that I could use for when I have to apply that equation to multiple different "a.dt" items throughout the same code.   Something like this, though I already know this doesn't work exactly like this:
%macro dateChange(dt1);
  newDt = year(datepart(dt1))*10000+month(datepart(dt1))*100+day(datepart(dt1));
  %put &newDt;
%mend

proc sql;
select %dateChange(a.dt) from somewhere;
quit;

This would enable me to pull be able to pull a date value from multiple different tables throughout the code without having to rewrite the equation on each one of them.   As I said though, I'm not entirely certain this is something that's even possible but I figured I'd go ahead and ask.   Appreciate any help! 

A:

You are very close.   Place just the computation part in the macro.   The macro will emit the computation source code. 
%macro dateChange(sas_datetime);
   year (datepart(&sas_datetime))*10000 + 
   month(datepart(&sas_datetime))*100 + 
   day  (datepart(&sas_datetime))
%mend;

proc sql;
  select %dateChange(a.dt) as dt_changed from somewhere as a;
quit;

The computation is changing the date time value to a representation that is the date part in format yymmdd6.   So an alternative could be
%macro dt_to_ymdNum(datetime); 
  input(put(datepart(&datetime),yymmdd6.),  6.) 
%mend;

proc sql;
  select %dt_to_ymdNum(a.dt) as dt_as_datenum from somewhere as a;
quit;

I would be moderately pissed at the data governance that signed off on a date value being encoded as 
yy * 10000 + mm * 100 + dd

in the data store.   You might want to be sure that is the actual case because it would be unusual in a new design but could be expected to be found in legacy data tables.