title: Checking for variable type in SAS-Macro
body: <p>I am trying to summarize my variables using proc sql and proc freq procedures in a macro. </p>
  
  <p>Here is the code:</p>
  
  <pre><code>%macro des_freq(input= ,vars= );
    %let n=%sysfunc(countw(&amp;vars));
    %let binary=NO;
    %do i = 1 %to &amp;n;
      %let values = %scan(&amp;vars, &amp;i);
        %if %datatyp(&amp;values)=NUMERIC %then %do;
          proc summary data = &amp;input;
            output out=x min(&amp;values)=minx max(&amp;values)=maxx;
          run;
          data _null_;
            set x;
            if minx = 0 and maxx = 1 then call symputx('binary','YES');
          run;
          %if &amp;binary = YES %then %do;
            proc sql;
              select segment_final,
                    (sum(case when &amp;values = 1 then 1 else 0 end)/ count(*)) * 100      as &amp;values._percent
              from &amp;input
              group by segment_final;
            quit;
          %end;
          %else %do;
            proc freq data =&amp;input;
              tables segment_final*&amp;values/nofreq nopercent nocol;
            run;
          %end;
        %end;
  
       %else %do;
          proc freq data =&amp;input;
             tables segment_final*&amp;values/nofreq nopercent nocol;
          run;
       %end;
    %end;
  %mend;
  </code></pre>
  
  <p>My variables can be numeric or character. If it's numeric, it can 2 more distinct values. </p>
  
  <p>I want % of 1's in a binary variable by segments(hence proc sql) and % of all distinct variables for each segment(hence proc freq). </p>
  
  <p>My first if statement is checking whether the variable if numeric or not and then if its numeric, next few steps is checking if its binary or not. If its binary then execute the proc sql else execute proc freq.  </p>
  
  <p>If the variable is character then just execute the proc freq. </p>
  
  <p>I am not able to figure out how to check if my variable is numeric or not. I tried %SYSFUNC(Vartype), %isnum and %DATATYP. None of them seem to work. Please help!!</p>