Hi guys
I have a little problem.
I have two lists (setlist1, setlist2) and i want to get the following result setlist3 = setlist1 \ setlist2 (setlist1 except setlist2).
%let setlist1 = FDBW_GC.GC__373013 FDBW_GC.GC__373014 FDBW_GC.GC__373015 FDBW_GC.GC__373016
FDBW_GC.GC__373017 FDBW_GC.GC__373018 FDBW_GC.GC__373019 FDBW_GC.GC__373113 FDBW_GC.GC__373114
FDBW_GC.GC__373115 FDBW_GC.GC__373116 FDBW_GC.GC__373117 FDBW_GC.GC__373118 FDBW_GC.GC__373119
FDBW_GC.GC__373213 FDBW_GC.GC__373214 FDBW_GC.GC__373215 FDBW_GC.GC__373216 FDBW_GC.GC__373217
FDBW_GC.GC__373218 FDBW_GC.GC__373219 FDBW_GC.GC__373313 FDBW_GC.GC__373314 FDBW_GC.GC__373315;
%let setlist2 = FDBW_GC.GC__373013 FDBW_GC.GC__373014 FDBW_GC.GC__373015 FDBW_GC.GC__373016
FDBW_GC.GC__373017 FDBW_GC.GC__373018 FDBW_GC.GC__373019 FDBW_GC.GC__373113 FDBW_GC.GC__373114
FDBW_GC.GC__373115 FDBW_GC.GC__373116 FDBW_GC.GC__373117 FDBW_GC.GC__373118 FDBW_GC.GC__373119;
result
%let setlist3 = FDBW_GC.GC__373213 FDBW_GC.GC__373214 FDBW_GC.GC__373215 FDBW_GC.GC__373216 FDBW_GC.GC__373217
FDBW_GC.GC__373218 FDBW_GC.GC__373219 FDBW_GC.GC__373313 FDBW_GC.GC__373314 FDBW_GC.GC__373315;
Thank you in advance for your help.
Best wishes.
Here is a simple macro that does the trick:
%macro listdiff(a,b);
%local i w;
%do i=1 %to %sysfunc(countw(&a));
%let w=%scan(&a,&i,%str( ));
%if not %sysfunc(indexw(&b,&w)) %then
%do; &w%end;
%end;
%mend;
%let setlist3=%listdiff(&setlist1,&setlist2);
Here is a simple macro that does the trick:
%macro listdiff(a,b);
%local i w;
%do i=1 %to %sysfunc(countw(&a));
%let w=%scan(&a,&i,%str( ));
%if not %sysfunc(indexw(&b,&w)) %then
%do; &w%end;
%end;
%mend;
%let setlist3=%listdiff(&setlist1,&setlist2);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.