Just to help me understand a little more, in your SQL procedure, the &derivation_1. as &name_1. through &derivation_4. as &name_4. are the additional variables you want? So, in the case you presented, the var_count macro variable would resolve to 4? If that is the case, then I believe the below code would create as many columns called "&name_n" as the value of the var_count macro (in the case you presented, it would list 4 fields). Also, this is obviously assuming that you have values for the macro variables num, derivation, and name being called.
Hope this helps, if it's not what you're looking for, maybe give a better example of the data you have and what you'd like to see.
Also, just an observation, but you have the event type as a character format in the _events_ data set and a numeric format in the edd_derivations data set. Was that intended, or do you need to add/remove "" from one of the SQL procedures?
proc sql noprint;
select count(*) into: var_count
from edd_derivations
where event_type=#
quit;
%macro create;
proc sql;
create table _&num as
select &standard_vars,
%do i=1 %to &var_count;
%if &i=&var_count %then %do;
&derivation_&i as &name_&i
%end;
%else %do;
&derivation_&i as &name_&i,
%end;
%end;
from _events_
where event_type="&num";
quit;
%mend;
%create;
... View more