<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: A Macro to Run Different Macros for Different Data Types in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-to-Run-Different-Macros-for-Different-Data-Types/m-p/452763#M114299</link>
    <description>&lt;P&gt;You cannot use sas functions directly within a macro code but under %sysfunc sas macro function.&lt;/P&gt;
&lt;P&gt;Try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro please_help(dataset, var1);
        %let dsid = %sysfunc(open(&amp;amp;dataset));
	%if %sysfunc(vartype(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid, &amp;amp;var1)))) = C %then %do;
		%cat_macro(&amp;amp;dataset, &amp;amp;var1);
	%end;
	%else %do;
		%num_macro(&amp;amp;dataset, &amp;amp;var1);
	%end;&lt;BR /&gt;        %let dsid = %sysfunc(close(&amp;amp;dsid));
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Alternativly you can try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro my_run  (dataset, var);
       data _null_;
             dsid = open("&amp;amp;dataset");
             if dsid &amp;gt; 0 then do;
                   if vartype(dsid, varnum(dsid,&amp;amp;var)) = 'C'
                   then call execute("%cat_macro(&amp;amp;dataset, &amp;amp;var)" );
                   else call execute("%num_macro(&amp;amp;dataset, &amp;amp;var)" );  &lt;BR /&gt;                dsid = close(dsid);&lt;BR /&gt;             end;
     run;
%mend;
%my_run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Apr 2018 11:41:31 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2018-04-10T11:41:31Z</dc:date>
    <item>
      <title>A Macro to Run Different Macros for Different Data Types</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-to-Run-Different-Macros-for-Different-Data-Types/m-p/452760#M114298</link>
      <description>&lt;P&gt;Hi all,&lt;BR /&gt;&lt;BR /&gt;I'm new to SAS and SAS Macro and I'm having trouble with this. I'm trying to write a macro that will&amp;nbsp;call one macro for categorical data, and another for numerical data. This is what I've tried so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro please_help(dataset, var1);

	%if vartype(&amp;amp;dataset, varnum(&amp;amp;dataset, &amp;amp;var1))=C %then %do;
		%cat_macro(&amp;amp;dataset, &amp;amp;var1);
	%end;
	%else %do;
		%num_macro(&amp;amp;dataset, &amp;amp;var1);
	%end;
%mend;&lt;/PRE&gt;&lt;P&gt;I'm getting the following error:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;ERROR: Required operator not found in expression: vartype(&amp;amp;dataset, varnum(&amp;amp;dataset, &amp;amp;var1))=C&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anyone suggest a correct way to find what type of data is entered, or maybe a different approach? I have also tried vtype and vtypex instead of vartype, and got the same error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 10:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-to-Run-Different-Macros-for-Different-Data-Types/m-p/452760#M114298</guid>
      <dc:creator>Sean100</dc:creator>
      <dc:date>2018-04-10T10:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro to Run Different Macros for Different Data Types</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-to-Run-Different-Macros-for-Different-Data-Types/m-p/452763#M114299</link>
      <description>&lt;P&gt;You cannot use sas functions directly within a macro code but under %sysfunc sas macro function.&lt;/P&gt;
&lt;P&gt;Try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro please_help(dataset, var1);
        %let dsid = %sysfunc(open(&amp;amp;dataset));
	%if %sysfunc(vartype(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid, &amp;amp;var1)))) = C %then %do;
		%cat_macro(&amp;amp;dataset, &amp;amp;var1);
	%end;
	%else %do;
		%num_macro(&amp;amp;dataset, &amp;amp;var1);
	%end;&lt;BR /&gt;        %let dsid = %sysfunc(close(&amp;amp;dsid));
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Alternativly you can try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro my_run  (dataset, var);
       data _null_;
             dsid = open("&amp;amp;dataset");
             if dsid &amp;gt; 0 then do;
                   if vartype(dsid, varnum(dsid,&amp;amp;var)) = 'C'
                   then call execute("%cat_macro(&amp;amp;dataset, &amp;amp;var)" );
                   else call execute("%num_macro(&amp;amp;dataset, &amp;amp;var)" );  &lt;BR /&gt;                dsid = close(dsid);&lt;BR /&gt;             end;
     run;
%mend;
%my_run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 11:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-to-Run-Different-Macros-for-Different-Data-Types/m-p/452763#M114299</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-04-10T11:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro to Run Different Macros for Different Data Types</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-to-Run-Different-Macros-for-Different-Data-Types/m-p/452765#M114301</link>
      <description>&lt;P&gt;Create a dataset with variable attributes from dictionary.columns, and then use call execute from that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table control as select libname,memname,name,type from dictionary.columns where libname = upcase("&amp;amp;lib.") and memname = upcase ("&amp;amp;dataset.") and upcase(name) = upcase("&amp;amp;var1.");
quit;

data _null_;
if type = 'char'
then call execute(cats('%cat_macro(',libname,'.',memname,',',name,');'));
else call execute(cats('%num_macro(',libname,'.',memname,',',name,');'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Apr 2018 11:18:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-to-Run-Different-Macros-for-Different-Data-Types/m-p/452765#M114301</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-10T11:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: A Macro to Run Different Macros for Different Data Types</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-Macro-to-Run-Different-Macros-for-Different-Data-Types/m-p/452767#M114303</link>
      <description>Thanks a million, I tried the first method and it worked perfectly!</description>
      <pubDate>Tue, 10 Apr 2018 11:27:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-Macro-to-Run-Different-Macros-for-Different-Data-Types/m-p/452767#M114303</guid>
      <dc:creator>Sean100</dc:creator>
      <dc:date>2018-04-10T11:27:06Z</dc:date>
    </item>
  </channel>
</rss>

