<?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: Loop of variable in proc freq in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-of-variable-in-proc-freq/m-p/353797#M82614</link>
    <description>&lt;P&gt;Thank you to you two!&lt;/P&gt;</description>
    <pubDate>Wed, 26 Apr 2017 17:26:04 GMT</pubDate>
    <dc:creator>Shawn08</dc:creator>
    <dc:date>2017-04-26T17:26:04Z</dc:date>
    <item>
      <title>Loop of variable in proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-of-variable-in-proc-freq/m-p/353771#M82600</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;New here, I hope that I'm am posting my question in the good location.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my previous work experience, I used STATA and Eviews. Now, in my new job, I must use SAS and therefore I am currently learning it. However I would have a question about loops.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to run a proc freq for many variables.&lt;/P&gt;&lt;P&gt;Here what the proc freq looks like for one variable:&lt;/P&gt;&lt;P&gt;proc freq data=ALL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; table COMPLIANCE_PC1 / binomial(level=1) alpha=.05;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have around 15 more variables than COMPLIANCE_PC1 and I would like to learn how to loop the variable instead of writing the proq freq for each variable individually.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought that I could do the following lines, but it doesn't work.&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; loop(var);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;proc freq data=ALL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; table &amp;amp;var&amp;nbsp;/ binomial(level=1) alpha=.05;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; loop;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;loop&lt;/I&gt;&lt;/STRONG&gt;(COMPLIANCE_PC1);&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;loop&lt;/I&gt;&lt;/STRONG&gt;(COMPLIANCE_PC2a);&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;loop&lt;/I&gt;&lt;/STRONG&gt;(COMPLIANCE_OTH2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance,&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 16:00:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-of-variable-in-proc-freq/m-p/353771#M82600</guid>
      <dc:creator>Shawn08</dc:creator>
      <dc:date>2017-04-26T16:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: Loop of variable in proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-of-variable-in-proc-freq/m-p/353773#M82602</link>
      <description>&lt;P&gt;A possible solution for you:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE COLNAMES AS SELECT NAME FROM DICTIONARY.COLUMNS WHERE MEMNAME = 'ALL';
QUIT;

/*CREATE A MACRO THAT WE WILL USE TO UPDATE NEWNAME WITH THE SPECIFIED CRITERIA*/
%MACRO LOOP(COLNAME);
proc freq data=ALL;
          table &amp;amp;COLNAME / binomial(level=1) alpha=.05;
run;
%MEND;

/*EXECUTE THE MACRO FOR EACH OF THE OLD NAMES*/
DATA COLNAMES;
SET COLNAMES;
CALL EXECUTE("%LOOP("||TRIM(NAME)||")");
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2017 16:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-of-variable-in-proc-freq/m-p/353773#M82602</guid>
      <dc:creator>thomp7050</dc:creator>
      <dc:date>2017-04-26T16:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Loop of variable in proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-of-variable-in-proc-freq/m-p/353778#M82605</link>
      <description>&lt;P&gt;PROC FREQ allows you to add multiple TABLE statements.&amp;nbsp; You only need a single PROC FREQ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition, a TABLE statement lets you include many table requests (just supply a list of variable names separated by spaces).&amp;nbsp; However, the options after the slash would likely apply to just one of the tables, so&amp;nbsp; you might need to revert to Plan A and supply many TABLE statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest avoiding macro language for now.&amp;nbsp; All it will do for&amp;nbsp;you is construct a program (it won't process your data).&amp;nbsp; It's more important to spend your time learning what the program can or should look like.&amp;nbsp; Once you have more possible programming techniques available, it would become appropriate to consider macro language.&amp;nbsp; In this case, generating 15 PROC FREQs (rather than a single PROC FREQ with multiple TABLE statements) would take much longer to run.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 16:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-of-variable-in-proc-freq/m-p/353778#M82605</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-26T16:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Loop of variable in proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-of-variable-in-proc-freq/m-p/353797#M82614</link>
      <description>&lt;P&gt;Thank you to you two!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 17:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-of-variable-in-proc-freq/m-p/353797#M82614</guid>
      <dc:creator>Shawn08</dc:creator>
      <dc:date>2017-04-26T17:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: Loop of variable in proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-of-variable-in-proc-freq/m-p/353826#M82636</link>
      <description>&lt;P&gt;And for added fun the tables statement will allow some moderately complex requests.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tables (a b c) *( s t u v) ; would create a crosstab of each variable listed inside the first set of () with each in the second:&lt;/P&gt;
&lt;P&gt;a*s a*t a*u a*v b*s b*t etc. And you can multiples of those.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note also that&lt;/P&gt;
&lt;P&gt;Proc freq data=somedatasetname;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Will run frequencies on every single variable in the data set though only the basic counts and percent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you want to look into variable lists. There are several ways to refer to groups of variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tables bac: / &amp;lt;options&amp;gt;; would generate output for each variable&amp;nbsp;whose name&amp;nbsp;starts with the character sequence&amp;nbsp;bac.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 17:57:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-of-variable-in-proc-freq/m-p/353826#M82636</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-26T17:57:56Z</dc:date>
    </item>
  </channel>
</rss>

