Create macro that is subset of other macro lists SAS -
i have 3 lists of macros have been created program, , i'm looking easy way eliminate dupes lists without looping through process created them.
%let a=(1, 2, 3, 4); %let b=(2, 8, 12); %let c=(1, 3, 5, 7);
what want 3 new variables have overlap values eliminated, this:
%let a_mod=(4); %let b_mod=(8, 12); %let c_mod=(5, 7);
i know there straightforward way in sas. thoughts? thanks.
what @joe said in comment correct. macro variables shouldn't used hold data; that's datasets for. solution straight addresses problem using macro functions , logic fragile , error prone. here approach uses datasets. it's not exclusively inelegant, @ to the lowest degree in opinion.
in comment mentioned it's possible store values datasets prior creating macro lists. that's great! i'll begin assuming have 3 datasets, a
, b
, , c
, containing values in mutual variable called v
.
first want bring together 3 datasets.
proc sql; create table abc select a.v a, b.v b, c.v c total bring together b on a.v = b.v total bring together c on a.v = c.v quit;
in resulting dataset, here called abc
, have columns a
, b
, , c
, each containing values dataset of same name. since datasets total joined, of values present. in given row, if 1 of a
, b
, , c
non-missing, have non-duplicate.
now can separate values out, omitting duplicates, akin a_mod
, etc. macro lists.
data a_mod(keep=a) b_mod(keep=b) c_mod(keep=c); set abc; if n(a, b, c) = 1 do; if ne . output a_mod; else if b ne . output b_mod; else if c ne . output c_mod; end; run;
the n()
function counts number of non-missing arguments.
now if need lists 1 time again whatever final utilize may be, can recreate them using into:
clause in proc sql
, example:
proc sql noprint; select into: a_mod a_mod separated ', '; quit; %let a_mod = (&a_mod); /* surrounding parentheses */
while want in case of few lists in question, it's note simple approach such 1 gets ugly and/or annoying if have ton of lists.
macros sas
No comments:
Post a Comment