<?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 Creating loop for proc freq in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-loop-for-proc-freq/m-p/728683#M226721</link>
    <description>&lt;P&gt;I have the following data&lt;/P&gt;&lt;P&gt;DATA HAVE;&lt;BR /&gt;input yr_2001 yr_2002 yr_2003 area;&lt;BR /&gt;cards;&lt;BR /&gt;1 1 1 3&lt;BR /&gt;0 1 0 4&lt;BR /&gt;0 0 1 3&lt;BR /&gt;1 0 1 6&lt;BR /&gt;0 0 1 4&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to do the following proc freq for variable yr_2001 to yr_2003.&lt;/P&gt;&lt;P&gt;proc freq data=have;&lt;BR /&gt;table yr_2001*area;&lt;BR /&gt;where yr_2001=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way I can do it without having to repeat it for each year, may be using a loop for proc freq??&lt;/P&gt;</description>
    <pubDate>Wed, 24 Mar 2021 08:22:11 GMT</pubDate>
    <dc:creator>Priyamvada07</dc:creator>
    <dc:date>2021-03-24T08:22:11Z</dc:date>
    <item>
      <title>Creating loop for proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-loop-for-proc-freq/m-p/728683#M226721</link>
      <description>&lt;P&gt;I have the following data&lt;/P&gt;&lt;P&gt;DATA HAVE;&lt;BR /&gt;input yr_2001 yr_2002 yr_2003 area;&lt;BR /&gt;cards;&lt;BR /&gt;1 1 1 3&lt;BR /&gt;0 1 0 4&lt;BR /&gt;0 0 1 3&lt;BR /&gt;1 0 1 6&lt;BR /&gt;0 0 1 4&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to do the following proc freq for variable yr_2001 to yr_2003.&lt;/P&gt;&lt;P&gt;proc freq data=have;&lt;BR /&gt;table yr_2001*area;&lt;BR /&gt;where yr_2001=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way I can do it without having to repeat it for each year, may be using a loop for proc freq??&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 08:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-loop-for-proc-freq/m-p/728683#M226721</guid>
      <dc:creator>Priyamvada07</dc:creator>
      <dc:date>2021-03-24T08:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creating loop for proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-loop-for-proc-freq/m-p/728685#M226722</link>
      <description>&lt;P&gt;Your issue is bad data structure. See Maxim 19.&lt;/P&gt;
&lt;P&gt;Transpose, then it's easy:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input yr_2001 yr_2002 yr_2003 area;
cards;
1 1 1 3
0 1 0 4
0 0 1 3
1 0 1 6
0 0 1 4
;

proc transpose
  data=have
  out=long (
    where=(col1 = 1)
  )
;
by area notsorted;
var yr:;
run;

proc freq data=long;
tables _name_*area;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Mar 2021 08:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-loop-for-proc-freq/m-p/728685#M226722</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-24T08:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating loop for proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-loop-for-proc-freq/m-p/728686#M226723</link>
      <description>&lt;P&gt;Start by transposing the data, so that do you don't have "data" in variable-names, then use by-statement in proc freq to create a table for each year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data transposed;
   set have;

   length year $ 4 value 8;
   
   array years yr_:;
   
   do i = 1 to dim(years);
      year = substr(vname(years[i]), 4);
      value = years[i];
      if value then output;
   end;
      
   drop yr_: i;
run;

proc sort data=transposed out=sorted;
   by year;
run;

proc freq data=sorted;
   by year;
   table value*area;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Mar 2021 08:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-loop-for-proc-freq/m-p/728686#M226723</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-03-24T08:34:11Z</dc:date>
    </item>
  </channel>
</rss>

