%macro genfmatn( /* --- this macro is a variation of genfmat that uses numeric args.*/ /* update history: 8-18-92: coded. 2-21-96: modifying for AIX. Change labellen default to 40. */ sasin=, argvar=, /* single numeric argument */ labelvar=areaname, /* name of character variable used for result values (labels) */ labellen=40, /* number of characters to be kept in label */ intrvls=0, /* set intrvls=1 to have macro collapse consecutive value with the same result (i.e. value for labelvar) into an interval. labelvar must be the name of a variable in &sasin. a by statement will be generated */ keepvars=, /* other variables from input dataset to be kept (for selecting purposes). use keepvars=_all_ to specify that you want all variables from source dataset kept. this will allow you to create argument and/or label variables using a slctedit macro--they will not have to already exist on the sasin dataset */ slctedit=, /* name of user exit macro to edit or filter dataset */ noblanks=0, /* specify noblanks=1 to suppress outputting blank labels */ other=, /* char string to be assigned with other= format spec */ source=0, /* specify source=1 if you want included text listed on the sas log */ print=, /* specify print=print if you want print option passed to proc format */ textfile=text, /* ddname of (usually temporary) file where generated source code is to be written */ mod= , /* specify mod=mod to write mod to textfile */ fmatname=, /* name of the format module, (omit leading $) */ fmatlib=saslib, /* ddname of sas format (load module) library where permanent sas format codes are to be stored */ runproc=1, /* specify runproc=0 to not invoke proc format */ )/stmt; options dquote; data _null_; set &sasin %if &keepvars ne _all_ %then (keep=&argvar &labelvar &keepvars); end=eod; %if &intrvls %then %do; by &labelvar notsorted; %end; file &textfile &mod; retain tic "'" ticetic "'='" ticdtic "'-'"; if _n_ = 1 then put @1 "proc format ddname=&fmatlib &print ;"/ @3 "value &fmatname "; if _n_=0 then go to afterput; *<---dummy reference; %if &slctedit ne %str() %then %&slctedit; *--we now have the argument value and the result value. the problem of embedded delimiters (single quotes) is handled by removing them with the compress function.--*; &labelvar=compress(&labelvar,tic); file &textfile; arg_=&argvar; %*---logic added here 5/89 to check for the &intrvls option and, if set, generate only one interval (va1l-val2=result) per result. may not do total collapsing since input set is typically sorted by the argvar instead of the labelvar-; %if &intrvls %then %do; if first.&labelvar then arg1_=&argvar; retain arg1_; if last.&labelvar then do; %if &noblanks %then %str(if &labelvar=' ' then goto afterput;); if first.&labelvar then put @2 arg_ "=" tic $1. &labelvar $char&labellen.. tic $1. ; *--write 1 arg=label line--*; else put @5 arg1_ "-" arg_ "=" tic $1. &labelvar $char&labellen.. tic $1.; *--write one interval line-; end; %end; %else %do; %if &noblanks %then %str(if &labelvar eq ' ' then goto afterput;); put @5 arg_ "=" tic $1. &labelvar $char&labellen.. tic $1. ; *--write 1 arg=label line--*; %end; afterput: %if &other ne %then %do; if eod then put / "other=&other" ; %end; if eod then put ";"; run; %if &runproc %then %do; %include &textfile %if &source=0 %then %str(/nosource2); %end; ;; *<---extra semicolon required in case none was generated at the end of the text file (happens when user filters last obs)-; run; %mend genfmatn;