<?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: proc sql  performing repeat calculations and creating a table of the results in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209369#M51881</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Gergely. That worked. I didn't think about the 'group by' ! @slchen...I was wanting to avoid the using keyword names. But, will try this for another scenario. Thanks for the suggestion on the 'sum' function instead of count.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 May 2015 13:41:15 GMT</pubDate>
    <dc:creator>dr2014</dc:creator>
    <dc:date>2015-05-05T13:41:15Z</dc:date>
    <item>
      <title>proc sql  performing repeat calculations and creating a table of the results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209366#M51878</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I have to calculate proportions of 'yes' answers for group1. In group1 there are multiple agencies. Within each agency (represented by agencyid ) are several units (represented by unitid). For a survey conducted for the group1, I need to calculate the proportion of 'yes' answers for a set of questions (represented as questionid ) across all units in an agency. Calculation is as follows:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Numerator&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;= &lt;SPAN style="text-decoration: underline;"&gt; (Sum of all 'yes' answers&amp;nbsp; by all units in the agency&amp;nbsp; / 24))&lt;/SPAN&gt;&amp;nbsp; * 100&lt;/P&gt;&lt;P&gt;Denominator&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; number of units within the agency&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;24 represents total number of questions&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code : &lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; create table p as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;select distinct agencyid, count(case answer when &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'yes'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; then &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; else &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; end) as yes_count,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((count(case answer when &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'yes'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; then &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; else &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; end))/&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;24&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;) as numerator,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(distinct unitid) as denominator, ((calculated numerator/calculated denominator)*&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;100&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;) as proportion&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; from test1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; where questionid in (&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'Q1'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'Q2'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'Q3'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;) and agencyid=18&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;I want to repeat this calculation for other agencyid's in the group. However, the values are not consecutive. For example , for this group1, the agencyid's are 18,19 and 36. I offcourse&amp;nbsp; knew these 3 agencies by running a proc freq. Instead of doing that, I would like to create a generic code where the calculation starts with the minimum value of the agencyid and ends with the maximum value and ignores the non-existing values between 19 to 36. It should create a table (just like table p -mentioned above) , but also include calculations for other agencies such as :&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;SPAN style="text-decoration: underline;"&gt;Group1:&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;agencyid yes_count numerator denominator proportion&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;18&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;19&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;36&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;I also created a keyword macro , but it will be very tedious to then stack the individual datasets especially for groups with plenty of agencies. here is that code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; v1=18;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; v2=19;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; v3=36;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;%macro&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; aid (v);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; create table p&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: teal; background: white;"&gt;v.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;select distinct agencyid, count(case answer when &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'yes'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; then &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; else &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; end) as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yes_count,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; ((count(case answer when &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'yes'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; then &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; else &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; end))/&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;24&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;) as numerator,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(distinct unitid) as denominator, ((calculated numerator/calculated denominator)*&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;100&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;) as proportion&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; from test1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; where questionid in (&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'Q1'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'Q3'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'Q5'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;) and agencyid=&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: teal; background: white;"&gt;v.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;%mend&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; faid;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;%&lt;STRONG&gt;&lt;EM&gt;faid&lt;/EM&gt;&lt;/STRONG&gt; (&amp;amp;v1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;%&lt;STRONG&gt;&lt;EM&gt;faid&lt;/EM&gt;&lt;/STRONG&gt; (&amp;amp;v2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;%&lt;STRONG&gt;&lt;EM&gt;faid&lt;/EM&gt;&lt;/STRONG&gt; (&amp;amp;v3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please advice and let me know your thoughts.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;Thanks !&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2015 20:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209366#M51878</guid>
      <dc:creator>dr2014</dc:creator>
      <dc:date>2015-05-04T20:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  performing repeat calculations and creating a table of the results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209367#M51879</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;Would this worki?:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;create table p as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;select agencyid, count(case answer when &lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: purple; background-position: initial;"&gt;'yes'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt; then &lt;/SPAN&gt;&lt;STRONG style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: teal; background-position: initial;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt; else &lt;/SPAN&gt;&lt;STRONG style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: teal; background-position: initial;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt; end) as yes_count,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((count(case answer when &lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: purple; background-position: initial;"&gt;'yes'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt; then &lt;/SPAN&gt;&lt;STRONG style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: teal; background-position: initial;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt; else &lt;/SPAN&gt;&lt;STRONG style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: teal; background-position: initial;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt; end))/&lt;/SPAN&gt;&lt;STRONG style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: teal; background-position: initial;"&gt;24&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;) as numerator,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(distinct unitid) as denominator, ((calculated numerator/calculated denominator)*&lt;/SPAN&gt;&lt;STRONG style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: teal; background-position: initial;"&gt;100&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;) as proportion&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;from test1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;&amp;nbsp; where questionid in (&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: purple; background-position: initial;"&gt;'Q1'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: purple; background-position: initial;"&gt;'Q2'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: purple; background-position: initial;"&gt;'Q3'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="color: black; font-size: 10pt; font-style: inherit; font-family: 'Courier New'; background-position: initial;"&gt;group by agencyid&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2015 21:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209367#M51879</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2015-05-04T21:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  performing repeat calculations and creating a table of the results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209368#M51880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure whether this is what you need:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro aid (v);&lt;/P&gt;&lt;P&gt;%let i=1;&lt;/P&gt;&lt;P&gt;%do %while (%scan(&amp;amp;v,&amp;amp;i)ne);&lt;/P&gt;&lt;P&gt;%let var=%scan(&amp;amp;v,&amp;amp;i);&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table p&amp;amp;var. as&lt;/P&gt;&lt;P&gt;select distinct agencyid, sum(answer='yes') as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yes_count, sum(answer='yes')/24 as numerator,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(distinct unitid) as denominator, ((calculated numerator/calculated denominator)*100) as proportion&lt;/P&gt;&lt;P&gt;from test1&lt;/P&gt;&lt;P&gt;where questionid in ('Q1','Q3','Q5') and agencyid=&amp;amp;var.;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%let i=%eval(&amp;amp;i+1);&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend aid;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%aid(%str(18 19 36))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2015 23:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209368#M51880</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2015-05-04T23:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  performing repeat calculations and creating a table of the results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209369#M51881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Gergely. That worked. I didn't think about the 'group by' ! @slchen...I was wanting to avoid the using keyword names. But, will try this for another scenario. Thanks for the suggestion on the 'sum' function instead of count.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 May 2015 13:41:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209369#M51881</guid>
      <dc:creator>dr2014</dc:creator>
      <dc:date>2015-05-05T13:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  performing repeat calculations and creating a table of the results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209370#M51882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gregely and slchen,&lt;/P&gt;&lt;P&gt;Although Gregely's suggestion worked. I have one more calculation I need to make. I also need a column with an average value of the proportions. I am unable to use the avg function when I use the 'group by' option and have to perform another proc sql to get that column. Is there a way to do a subquery within the original SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I basically want the table to look like this now :&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;SPAN style="text-decoration: underline;"&gt;Group1:&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;agencyid yes_count numerator denominator proportion avg_proportion&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;18&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;19&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;36&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;create table p as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;select agencyid, count(case answer when &lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: purple; background-position: initial;"&gt;'yes'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt; then &lt;/SPAN&gt;&lt;STRONG style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: teal; background-position: initial;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt; else &lt;/SPAN&gt;&lt;STRONG style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: teal; background-position: initial;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt; end) as yes_count,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((count(case answer when &lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: purple; background-position: initial;"&gt;'yes'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt; then &lt;/SPAN&gt;&lt;STRONG style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: teal; background-position: initial;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt; else &lt;/SPAN&gt;&lt;STRONG style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: teal; background-position: initial;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt; end))/&lt;/SPAN&gt;&lt;STRONG style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: teal; background-position: initial;"&gt;24&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;) as numerator,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(distinct unitid) as denominator, ((calculated numerator/calculated denominator)*&lt;/SPAN&gt;&lt;STRONG style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: teal; background-position: initial;"&gt;100&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;) as proportion&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;from test1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;&amp;nbsp; where questionid in (&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: purple; background-position: initial;"&gt;'Q1'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: purple; background-position: initial;"&gt;'Q2'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: purple; background-position: initial;"&gt;'Q3'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="color: black; font-size: 10pt; font-style: inherit; font-family: 'Courier New'; background-position: initial;"&gt;group by agencyid&lt;/STRONG&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;create table q as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;select agencyid , yes_count, numerator, denominator, proportion, avg(proportion) as grp_avg,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;from p,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;Also with this code , the average value gets repeated for each row in the table.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;Please let me know.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black; background-position: initial;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 May 2015 15:25:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209370#M51882</guid>
      <dc:creator>dr2014</dc:creator>
      <dc:date>2015-05-05T15:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  performing repeat calculations and creating a table of the results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209371#M51883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table p as&lt;/P&gt;&lt;P&gt;select *, avg(proportion) as grp_avg from(select agencyid, count(case answer when 'yes' then 1 else 0 end) as yes_count,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((count(case answer when 'yes' then 1 else 0 end))/24) as numerator,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(distinct unitid) as denominator, ((calculated numerator/calculated denominator)*100) as proportion&lt;/P&gt;&lt;P&gt;from test1&lt;/P&gt;&lt;P&gt;where questionid in ('Q1','Q2','Q3')&lt;/P&gt;&lt;P&gt;group by agencyid);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 May 2015 16:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209371#M51883</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2015-05-05T16:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  performing repeat calculations and creating a table of the results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209372#M51884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks slchen. It did work. I have one more question. I wanted to have only the first row of the table to mention the value for grp_avg though. Would I need to create an id and then specify that.. id from 2 to eof grp_avg='&amp;nbsp;&amp;nbsp; '. What would be the best way to accomplish that ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 May 2015 18:26:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-performing-repeat-calculations-and-creating-a-table-of/m-p/209372#M51884</guid>
      <dc:creator>dr2014</dc:creator>
      <dc:date>2015-05-05T18:26:29Z</dc:date>
    </item>
  </channel>
</rss>

