3 ms·
I don't know Lisp, but I know SAS; are my macros Macros?
I have been wondering this for quite a while; I write a lot of SAS both for my dissertation and my research assistant duties. As a language it is a very strange beast (For example there are at least three if-then syntaxes (data if, matrix if, macro if, and assuming SQL has an if that's four, at least that I've found so far)). It has a "macro facility" which I will do my best to describe given my meager CS vocabulary. A SAS program is interpreted, not compiled, but if a & character is encountered, the program passes to a pre-compiler of sorts and & are translated into code and then interpreted. If && are encountered, they resolve to & and then a second pass with the pre-compiler is run, and so on. I've attached a code snippet below; This takes a data set and divides it into many datasets, one for each unique value in listdataset (I use this to change a comprehensive stock-returns dataset into aapl,goog,etc. returns databases) So, for the first iteration of the loop, dat_&&temp&k. resolves to dat_&temp1. which resolves in the second pre-compile to dat_goog or whatever temp1 was set to by
call symput('temp'||left(_n_), tempvar);
So, in just a few lines of macro code I can generate volumes of interpreted code. Does this make SAS a dialect of Lisp, or is the "macro facility" something else entirely?
%macro partition(listdataset,dataset, varinquotes, var1, var2, obs);
data &listdataset.;
set &listdataset.;
tempvar = trim(left(&var1.));
call symput('temp'||left(_n_), tempvar);
run;
%do k = 1 %to &obs.;
data dat_&&temp&k.;
set &dataset.;
if &var2.= "&&temp&k.";
run;
%end;
%mend partition;