<?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: Using PROC EXECUTE to call PROC TABULATE (please advise) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741788#M231941</link>
    <description>Unfortunately not. PROC FREQ treats everything as categorical. I have a mix of continuous and categorical.</description>
    <pubDate>Sun, 16 May 2021 22:18:37 GMT</pubDate>
    <dc:creator>MelissaM</dc:creator>
    <dc:date>2021-05-16T22:18:37Z</dc:date>
    <item>
      <title>Using PROC EXECUTE to call PROC TABULATE (please advise)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741759#M231926</link>
      <description>&lt;P&gt;I would like your help (or other advice) how to do this.&lt;/P&gt;
&lt;P&gt;I have a long list of numeric and character variables to tabulate. Very easy. Very tedious.&lt;/P&gt;
&lt;P&gt;I believe I can run a macro, similar to the one below (which doesn't work, by the way), to determine if the variable is NUMERIC or CHARACTER, and then direct it to the appropriate macro.&lt;/P&gt;
&lt;P&gt;1) Can you assist with the macro?&lt;/P&gt;
&lt;P&gt;2) If not, thoughts on how this obviously common task can be done would be appreciated.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;------------------------------------------------------------&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DATA CARS;
	SET SASHELP.CARS;
RUN;

%macro TEMP(all_vars=);
	%let k=1;
	%let var = %scan(&amp;amp;all_vars, &amp;amp;k);
	%do %until(&amp;amp;var eq "END");

		 %if (%datatyp(&amp;amp;var)=NUMERIC ) %then %do;
		  %TABLECONT(DATA= CARS,BYVAR= ORIGIN,VAR=&amp;amp;var.);
		%end;
		%else %do;
		  %TABLECHAR(DATA= CARS,BYVAR= ORIGIN,VAR=&amp;amp;var.);
		%end;

	%let k = %eval(&amp;amp;k + 1);
	%let VAR = %scan(&amp;amp;all_vars, &amp;amp;k);
	%end;  
%mend temp;


%MACRO TABLECHAR(DATA= CARS,BYVAR= ORIGIN,VAR=);
	proc TABULATE DATA=CARS;
		class &amp;amp;var ORIGIN ;
	TABLE (&amp;amp;VAR ALL),(ORIGIN ALL) *(N="n" COLpctn= "%"*F=5.1);  
	RUN;
%mend TABLECHAR;
%MACRO TABLECONT (DATA= CARS,BYVAR= ORIGIN,VAR=);
	PROC TABULATE DATA=CARS  ;
	class origin;
	var &amp;amp;var;
	TABLE 	(&amp;amp;VAR  ),(ORIGIN ALL)
						*(N="n" mean='Mean'*F=8.1); 
	RUN;
%MEND TABLECONT;



%temp(ALL_vars=cylinders type weight msrp END);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;: Example with SASHELP.CARS now included.&lt;/P&gt;
&lt;P&gt;[&lt;FONT color="#FF0000"&gt;If you run it, you will have to manually cancel the submitted statements because DO WHILE is not working&lt;/FONT&gt;]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 May 2021 23:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741759#M231926</guid>
      <dc:creator>MelissaM</dc:creator>
      <dc:date>2021-05-16T23:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC EXECUTE to call PROC TABULATE (please advise)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741769#M231928</link>
      <description>&lt;P&gt;CALL EXECUTE is a data step routine. Since you only need to call a macro from within macro code, this is not needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if (%datatyp(&amp;amp;var)=NUMERIC ) %then %do;
  %TABLECONT(DATA= ,BYVAR= ,CONTVAR=&amp;amp;var.);
%end;
%else %do;
  %TABLECHAR(DATA= ,BYVAR= ,CHARVAR=&amp;amp;var.);
%end;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Supply the additional macro parameters as needed.&lt;/P&gt;</description>
      <pubDate>Sun, 16 May 2021 18:36:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741769#M231928</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-16T18:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC EXECUTE to call PROC TABULATE (please advise)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741782#M231938</link>
      <description>&lt;P&gt;This simpler program does something like what you are trying to do.&amp;nbsp; Would it be sufficient?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
   tables (&amp;amp;all_vars) * byvar / norow nopercent;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 May 2021 21:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741782#M231938</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-05-16T21:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC EXECUTE to call PROC TABULATE (please advise)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741788#M231941</link>
      <description>Unfortunately not. PROC FREQ treats everything as categorical. I have a mix of continuous and categorical.</description>
      <pubDate>Sun, 16 May 2021 22:18:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741788#M231941</guid>
      <dc:creator>MelissaM</dc:creator>
      <dc:date>2021-05-16T22:18:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC EXECUTE to call PROC TABULATE (please advise)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741791#M231943</link>
      <description>&lt;P&gt;You seem confused about what macro code does.&amp;nbsp; You use it to generate SAS code.&amp;nbsp; So figure out what SAS code you want to run.&amp;nbsp; Then figure out how it needs to change for numeric or character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your current code has two major problems.&lt;/P&gt;
&lt;P&gt;1) You are using the %DATATYP() to check if the NAME of your variable looks like a number or not.&amp;nbsp; Since numbers are not valid SAS variable names all of the variable names will look like characters to that macro.&lt;/P&gt;
&lt;P&gt;2) You are trying to run the CALL EXECUTE() statement outside of a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's start with what you have.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I have a long list of numeric and character variables to tabulate.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Your list of variable names does not really provide any useful information for coding without actually know what dataset the variable are in.&amp;nbsp; Variables do not exist independent of datasets.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So first question is what is the dataset you want to analyze?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you seem to be wanting to determine what type of analysis based on whether the variable should be treated as categorical or continuous.&amp;nbsp; &amp;nbsp;SAS only has two types of variables: fixed length character strings and floating point numbers.&amp;nbsp; But there is nothing that says that a categorical variable could not be a number.&amp;nbsp; For example month or quarter of a year are numbers, but you probably want to treat them as categories for this type of analysis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be much easier to just tell it which types of analysis you want for each variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro tables
(dsn=    /* Dataset name */
,catvars=  /* Space delimited list of categorical variables */
,contvars=  /* Space delimited list of continuous variables */
);
%local i var ;
%do i=1 %to %sysfunc(countw(&amp;amp;catvars,%str( )));
  %let var=%scan(&amp;amp;catvars,&amp;amp;i,%str( ));
PROC TABULATE DATA=&amp;amp;dsn;
  class &amp;amp;var byvar ;
  CLASSLEV &amp;amp;var / s=[indent=15 ];
  TABLE &amp;amp;var,(BYVAR ALL) *(N="n" COLpctn= "%"*F=5.1) ;
RUN;
%end;
%do i=1 %to %sysfunc(countw(&amp;amp;contvars,%str( )));
  %let var=%scan(&amp;amp;contvars,&amp;amp;i,%str( ));
PROC TABULATE DATA=&amp;amp;dsn;
  VAR &amp;amp;var ;
  CLASSLEV &amp;amp;var / s=[indent=15 ];
  TABLE &amp;amp;var,(BYVAR ALL) *(N="n" );
RUN;
%end;
%mend tables;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 May 2021 23:02:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741791#M231943</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-16T23:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC EXECUTE to call PROC TABULATE (please advise)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741793#M231945</link>
      <description>Kurt, Thank you so much. &lt;BR /&gt;After oh, another ? hrs, I still need your help.&lt;BR /&gt;For this round, I not only fixed my original message, but also used SASHELP.class so there's actual data.&lt;BR /&gt;The program will have to be manually stopped, unfortunately. But don't let that scare you.&lt;BR /&gt;I've actually been at this for a couple weeks, so I really appreciate the guidance.&lt;BR /&gt;</description>
      <pubDate>Sun, 16 May 2021 23:29:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741793#M231945</guid>
      <dc:creator>MelissaM</dc:creator>
      <dc:date>2021-05-16T23:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC EXECUTE to call PROC TABULATE (please advise)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741797#M231947</link>
      <description>Tom, &lt;BR /&gt;What I lack in macro skills might be analogous to what others lack in, say, social skills. &lt;BR /&gt;I remind you that we are all learning here. I ask that you be mindful of your tone.&lt;BR /&gt;That said; your interpretation of what I was doing incorrectly was spot on correct. &lt;BR /&gt;And more than that, I appreciate the amazing macro!</description>
      <pubDate>Mon, 17 May 2021 00:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-EXECUTE-to-call-PROC-TABULATE-please-advise/m-p/741797#M231947</guid>
      <dc:creator>MelissaM</dc:creator>
      <dc:date>2021-05-17T00:12:59Z</dc:date>
    </item>
  </channel>
</rss>

