I have a list of dataset variables in a macro variable called &allvars
. I have another macro variable called &contlist
that contains the variables in &allvars
that are continuous. I'm try to extract the variables in &allvars
which are not in &contlist
, i.e. are not continuous.
This is what I have:
%let binlist = &allvars;
%let i = 1;
%do %until( %scan(&var, &i, %str( )) = );
%let v = %scan(&var, &i, %str( ));
%let j = 1;
%do %until( %scan(&contlist, &j, %str( )) = );
%let c = %scan(&contlist, &j, %str( ));
%if %upcase(&v) = %upcase(&c) %then
%let binlist = %sysfunc(tranwrd(&binlist, &v, %str()));
%let j = %eval(&j + 1);
%end;
%let i = %eval(&i + 1);
%end;
%let binlist = %sysfunc(compbl(&binlist));
However, this causes a problem when variables have similar names, like so:
%let allvars = x x1 x2 x3;
%let contlist = x x1 x2;
The desired output here would be only x3
, but instead this produces 1 2 3
because of the call to TRANWRD
.
My only other thought would be to output both lists to datasets, merge them, keep only the records from allvars
not in contlist
, then create binlist
from those records. However, there has to be a simpler, more elegant solution.
Any ideas?