BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
makset
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

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);

View solution in original post

2 REPLIES 2
s_lassen
Meteorite | Level 14

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);
makset
Obsidian | Level 7
It works
Thank you
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 990 views
  • 1 like
  • 2 in conversation