As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Macro FindType

From sasCommunity
Jump to: navigation, search
 /*    name:
       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:
How Do I Find Out What That _TYPE_ Value Is from My MEANS Procedure?
Answer: The FINDTYPE Macro!
Dan Bruns, Chattanooga, TN
harvested for sas community wiki
by RJF2 2/19/2009 10:44:28 AM   *******/
%macro findtype
)/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);
    %else %if &Target. = _TYPE_ %then %let Flag = &I.;
%let Fid = %sysfunc(close(&Fid.));
%goto term;
%mend findtype;