Macro FindType
From sasCommunity
- Question:
- How Do I Find Out What That _TYPE_ Value Is from My MEANS Procedure?
- Answer: The FINDTYPE Macro!
- Dan Bruns, Chattanooga, TN
- http://www2.sas.com/proceedings/sugi31/043-31.pdf
/* name: findtype.sas
is.a: macro function
description: given a proc means/summary variable _type_
return a logical expression:
_type_ eq ?
where ? in 0, 1, 2, ... N(class vars)
purpose : simplify use of summary._type_
example :
Proc Print data = Libref.MySummary
(where = (%FindType(Libref.MySummary, var2 var4)
) );
from the paper:
Question:
How Do I Find Out What That _TYPE_ Value Is from My MEANS Procedure?
Answer: The FINDTYPE Macro!
Dan Bruns, Chattanooga, TN
http://www2.sas.com/proceedings/sugi31/043-31.pdf
harvested for sas community wiki
by RJF2 2/19/2009 10:44:28 AM *******/
%macro findtype
(table=
,vars=
)/des = ''
;
%local I Index Fid Flag Target;
%let Fid = %sysfunc(open(&Table,i));
%if not &Fid. %then %goto exit;%*return;
%let Vars = %upcase(&vars);
%let Flag = 0;
%let _Type_ = 0;
%do I = %sysfunc(attrn(&Fid.,nvars)) %to 1 %by -1;
%let Target = %upcase(%sysfunc(varname(&Fid.,&I.)));
%if &Flag. %then %do;
%let Index = 1;
%do %while (%length(%scan(&vars.,&index.)) > 0);
%if &Target = %scan(&Vars.,&Index.) %then
%let _type_ = %eval(&_type_. + 2**(&Flag. - &I. - 1));
%let index = %eval(&Index + 1);
%end;
%end;
%else %if &Target. = _TYPE_ %then %let Flag = &I.;
%end;
%let Fid = %sysfunc(close(&Fid.));
&_Type_
%goto term;
%Exit:;
%term:
%mend findtype;
References
- Frank Ferriola
- What’s Your _TYPE_? How to find the CLASS You Want in PROC SUMMARY
- http://www2.sas.com/proceedings/sugi27/p077-27.pdf