/**************************************************************/ /* custlist.sas */ /* */ /* Martin Bresser */ /* */ /* Create a custom list for where= or in= processing */ /* based on observations of a variable in a dataset */ /* */ /* Example: */ /* data test; */ /* set test2; */ /* if var in (%custlist(file=test3(where=(var2="ABC")),var3) */ /* then output; */ /* run; */ /* */ /* Selects all observations from test2 for which the value of*/ /* var has a value as var3 from test3 for which var2 has the */ /* value "ABC" */ /* */ /* Special features: */ /* Character values are single quoted */ /* Numeric values are not quoted */ /* Comma's between list is optional, commas are default */ /* komma=0 as third argument for no commas */ /* */ /**************************************************************/ %macro custlist(file=,var=,komma=1); %local dsid cpos type rc hlp; %let dsid=%sysfunc(open(&file)); %let cpos=%sysfunc(varnum(&dsid,&var)); %let type=%sysfunc(vartype(&dsid,&cpos)); %let rc=%sysfunc(fetch(&dsid)); %do %while (&rc = 0); %if &type=C %then %let hlp=%left(%nrbquote(%str(%')%qtrim(%nrbquote(%qsysfunc(getvarc(&dsid,&cpos))))%str(%'))); %else %let hlp=%sysfunc(getvarn(&dsid,&cpos)); %let rc=%sysfunc(fetch(&dsid)); %if ((&rc ne 0) or (&komma=0)) %then &hlp; %else &hlp,; %end; %let rc=%sysfunc(close(&dsid)); %mend;