%macro mvlist(v,nv,quotes=1,commas=1); %*--Originally coded 3-20-2003, adapted from csqlist. John Blodgett--; %*--Revised 3/22/2003 1:18PM --; %*--Accepts the NAME of a possibly multi-valued SELECT list parm. The 2nd positional parm, if specified, is the number of variables in the list. If nv is not specified then the macro tries to find a global variable named (&v)0 and uses its value as the list length. If it cannot determine a valid numeric value for nv it will fail with an error message. Otherwise, it will try to return a list of values which by default will be quoted and comma-separated. Resulting values are suitable for use as an argument witht the "in" function. For example, if v=cnty and nv=3 and we have values cnty1=010 cnty2==340 and cnty3=189 then the value returned would be "010","340","189". if v=table, nv is not specified but there is a global variable &table0 with a value of 5 then the macro will return a list comprised of the values of &table1 thru &table5. Specify quotes=0 to specify no quotes (for numeric lists presumably) Specify commas=0 to get a space delimited list instead of comma delimited. NOTE that the first parm is just a name and will usually not begin with an ampersand. The second parm is a value. It should either begin with an ampersand to reference a global variable with a numeric value or it should be a numeric constant. In most cases it will not even be specified and the macro will assume a reference to the global var with name the same as (v)0, where (v) is the value of the first parm. ---*; %local _i _ret _nv; %let _ret=; %if %superq(nv) eq %then %let _nv=&&&v.0; %else %let _nv=&nv; %if %qsubstr(%superq(_nv),1,1) = %nrbquote(&) %then %do; %put ***** ERROR: mvlist macro unable to determine the number of variables in the list.; %put ***** ERROR: mvlist macro unable to determine the number of variables in the list.; %put ***** ERROR: mvlist macro unable to determine the number of variables in the list.; %goto endmac; %end; %do _i=1 %to &_nv; %global &&v.&_i; %if "es %then "&&&v.&_i"; %else &&&v.&_i; %if &commas and &_i lt &_nv %then %str(,); %end; %endmac: %mend mvlist;