The ID statement automatically creates the variable names based on distinct values present in the Date column. Since the values begin with a number and SAS does not allow variable names to begin with a number, we add on a prefix (in this case, D is the prefix I used). So the first variable is D+30NOV2016 = D30NOV2016, and so on. Without providing a prefix, SAS would just put an underscore at the beginning of the variable names like _30NOV2016. With regard to automatically pulling in var names in your array, this is how you can do it: proc transpose data=real prefix=D_ out=realtrans (drop=_name_); /* added an underscore so that query below works, want to distinguish these variables from Department */
by department notsorted;
id date;
var sale;
run;
proc sql;
select name into :namevarlist separated by ' '
from dictionary.columns
where memname='REALTRANS'
and substr(name,1,2) ='D_';
quit;
DATA FINAL;
SET realtrans;
ARRAY SALE(3) &namevarlist.;
ARRAY SALE_DIFF(2);
DO I = 1 TO DIM(SALE_DIFF);
SALE_DIFF(I) = SALE(I + 1) - SALE(I);
END;
DROP I;
RUN;
... View more