<?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: Repeat the same procedure for all observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Repeat-the-same-procedure-for-all-observations/m-p/194956#M36666</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The following will give you the monthly competitor mean sales by product and city, assuming that other branches from the same company are competitors:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data have;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;infile datalines truncover;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;input Company_Nm $ Branch_Id $ City &amp;amp;$12. Product_ID $ Date :anydtdte6. Sales;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;format date yymmdd10.;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA1 Gainesville&amp;nbsp; XX Jan-11 10000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA2 Yreka&amp;nbsp; XX Jan-11 8000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA3 Yreka&amp;nbsp; XX Jan-11 5000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA4 San Francisco&amp;nbsp; XX Jan-11 4000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA5 Los Angeles&amp;nbsp; XX Jan-11 7000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA6 Donalsonville&amp;nbsp; XX Jan-11 12000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA7 Savannah&amp;nbsp; XX&amp;nbsp; Jan-11 80000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BBB BBB1 Yreka&amp;nbsp; XX Jan-11 1000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BBB BBB2 San Francisco&amp;nbsp; XX Jan-11 1000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BBB BBB3 Los Angeles&amp;nbsp; XX Jan-11 1000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BBB BBB4 Donalsonville&amp;nbsp; XX Jan-11 1000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BBB BBB5 Savannah&amp;nbsp; XX Jan-11 1000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select Company_Nm, Branch_Id, Product_Id, Date, Sales,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select mean(Sales) &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from have &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where Product_Id=a.Product_Id and date=a.date and not&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (Company_Nm = a.Company_Nm and Branch_Id = a.Branch_Id)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) as Competitor_Sale&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from have as a;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 08 Aug 2015 18:49:43 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2015-08-08T18:49:43Z</dc:date>
    <item>
      <title>Repeat the same procedure for all observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-the-same-procedure-for-all-observations/m-p/194954#M36664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;Below is small part of the dataset that I'm working with. The only difference is that my dataset contains many more company_Nm, branch_id, product_id and date.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 435px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl64" height="22" width="88"&gt;Company_Nm&lt;/TD&gt;&lt;TD class="xl64" style="border-left: none;" width="65"&gt;Branch_ID&lt;/TD&gt;&lt;TD class="xl64" style="border-left: none;" width="76"&gt;City &lt;/TD&gt;&lt;TD class="xl64" style="border-left: none;" width="76"&gt;Product_ID&lt;/TD&gt;&lt;TD class="xl65" style="border-left: none;" width="65"&gt;Date &lt;/TD&gt;&lt;TD class="xl64" style="border-left: none;" width="65"&gt;Sale&lt;/TD&gt;&lt;TD class="xl64" style="border-left: none;" width="65"&gt;Competitors_sale&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="22" style="border-top: none;"&gt;AAA&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;AAA1&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;Gainesville&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt; XX&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;Jan-11&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;10000&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl66" height="22" style="border-top: none;"&gt;AAA&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; text-align: -webkit-right;"&gt;AAA&lt;/SPAN&gt;2&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;Yreka&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt; XX&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;"&gt;Jan-11&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;8000&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl66" height="22" style="border-top: none;"&gt;AAA&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; text-align: -webkit-right;"&gt;AAA&lt;/SPAN&gt;3&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;Yreka&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt; XX&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;"&gt;Jan-11&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;5000&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="22" style="border-top: none;"&gt;AAA&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; text-align: -webkit-right;"&gt;AAA&lt;/SPAN&gt;4&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;San Francisco&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt; XX&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;Jan-11&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;4000&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="22" style="border-top: none;"&gt;AAA&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; text-align: -webkit-right;"&gt;AAA&lt;/SPAN&gt;5&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;Los Angeles&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt; XX&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;Jan-11&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;7000&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="22" style="border-top: none;"&gt;AAA&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; text-align: -webkit-right;"&gt;AAA&lt;/SPAN&gt;6&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;Donalsonville&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt; XX&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;Jan-11&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;12000&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="22" style="border-top: none;"&gt;AAA&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; text-align: -webkit-right;"&gt;AAA&lt;/SPAN&gt;7&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;Savannah&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt; XX&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;Jan-11&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;80000&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="22" style="border-top: none;"&gt;BBB&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;BBB1&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;Yreka&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt; &lt;SPAN style="font-size: 13.3333330154419px;"&gt;XX&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;Jan-11&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;1000&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="22" style="border-top: none;"&gt;BBB&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;BBB2&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;San Francisco&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt; &lt;SPAN style="font-size: 13.3333330154419px;"&gt;XX&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;Jan-11&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;1000&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="22" style="border-top: none;"&gt;BBB&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;BBB3&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;Los Angeles&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt; &lt;SPAN style="font-size: 13.3333330154419px;"&gt;XX&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;Jan-11&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;1000&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="22" style="border-top: none;"&gt;BBB&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;BBB4&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;Donalsonville&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt; &lt;SPAN style="font-size: 13.3333330154419px;"&gt;XX&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;Jan-11&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;1000&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="22" style="border-top: none;"&gt;BBB&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;BBB5&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;Savannah&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt; &lt;SPAN style="font-size: 13.3333330154419px;"&gt;XX&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;Jan-11&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;1000&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;For each specific &lt;STRONG&gt;Company_nm&lt;/STRONG&gt; and &lt;STRONG&gt;branch_id&lt;/STRONG&gt;,each row, I want to find other branches located in the same &lt;STRONG&gt;city&lt;/STRONG&gt;, let's say competitors. Then I need to take the average of sales among the competitors for the same &lt;STRONG&gt;product_id&lt;/STRONG&gt; and &lt;STRONG&gt;date&lt;/STRONG&gt; in that row, and put the value in the competitor_sale column.&lt;/P&gt;&lt;P&gt;Previously, I picked only one &lt;STRONG&gt;branch_id&lt;/STRONG&gt; as a pilot and did the same procedure for that. I may be able to extend my code to all rows by do loop, but I'm not sure what's the most efficient way. Below is my code, even though I'm think it's so ugly and inefficient. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data AAA1; &lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;if branch_id='AAA1';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql;&lt;/P&gt;&lt;P&gt;create table comp1 as&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from&amp;nbsp; &lt;SPAN style="font-size: 13.3333330154419px;"&gt;have&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;where city in (Select city from AAA1);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql;&lt;/P&gt;&lt;P&gt;create comp2 as&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from&amp;nbsp; &lt;SPAN style="font-size: 13.3333330154419px;"&gt;comp1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;where company_nm not in (Select company_nm from AAA1);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql ; &lt;/P&gt;&lt;P&gt; create table comp_rate as &lt;/P&gt;&lt;P&gt; select product_id, date,&amp;nbsp; &lt;/P&gt;&lt;P&gt; mean(rate) as Ave_comp format = 5.3&lt;/P&gt;&lt;P&gt; from comp2&lt;/P&gt;&lt;P&gt;group by&amp;nbsp; &lt;SPAN style="font-size: 13.3333330154419px;"&gt;product_id, date&lt;/SPAN&gt;; &lt;/P&gt;&lt;P&gt; quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data want;&lt;/P&gt;&lt;P&gt;merge AAA1 &lt;SPAN style="font-size: 13.3333330154419px;"&gt;comp_rate;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;by product_id date;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I really appreciate any and all suggestions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Aug 2015 15:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-the-same-procedure-for-all-observations/m-p/194954#M36664</guid>
      <dc:creator>m1986MM</dc:creator>
      <dc:date>2015-08-08T15:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat the same procedure for all observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-the-same-procedure-for-all-observations/m-p/194955#M36665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is an untested code , for every branch_id a dataset is created. Hope this is what you are expecting &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select distinct branch_id, count(distinct branch_id) into :id1-:id&amp;amp;sysmaxlong, :obs from have;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;obs;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;%do i = 1 %to &amp;amp;obs;&lt;/P&gt;&lt;P&gt;data &amp;amp;&amp;amp;id&amp;amp;i;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;if branch_id="&amp;amp;&amp;amp;id&amp;amp;i";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql;&lt;/P&gt;&lt;P&gt;create table comp1 as&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from&amp;nbsp; have&lt;/P&gt;&lt;P&gt;where city in (Select city from &amp;amp;&amp;amp;id&amp;amp;i);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql;&lt;/P&gt;&lt;P&gt;create table comp2 as&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from&amp;nbsp; comp1&lt;/P&gt;&lt;P&gt;where company_nm not in (Select company_nm from &amp;amp;&amp;amp;id&amp;amp;i);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql ;&lt;/P&gt;&lt;P&gt;create table comp_rate as&lt;/P&gt;&lt;P&gt;select product_id, date, &lt;/P&gt;&lt;P&gt;mean(rate) as Ave_comp format = 5.3&lt;/P&gt;&lt;P&gt;from comp2&lt;/P&gt;&lt;P&gt;group by&amp;nbsp; product_id, date;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data &amp;amp;&amp;amp;id&amp;amp;i;&lt;/P&gt;&lt;P&gt;merge &amp;amp;&amp;amp;id&amp;amp;i comp_rate;&lt;/P&gt;&lt;P&gt;by product_id date;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jag&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Aug 2015 17:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-the-same-procedure-for-all-observations/m-p/194955#M36665</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2015-08-08T17:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat the same procedure for all observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-the-same-procedure-for-all-observations/m-p/194956#M36666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The following will give you the monthly competitor mean sales by product and city, assuming that other branches from the same company are competitors:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data have;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;infile datalines truncover;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;input Company_Nm $ Branch_Id $ City &amp;amp;$12. Product_ID $ Date :anydtdte6. Sales;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;format date yymmdd10.;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA1 Gainesville&amp;nbsp; XX Jan-11 10000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA2 Yreka&amp;nbsp; XX Jan-11 8000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA3 Yreka&amp;nbsp; XX Jan-11 5000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA4 San Francisco&amp;nbsp; XX Jan-11 4000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA5 Los Angeles&amp;nbsp; XX Jan-11 7000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA6 Donalsonville&amp;nbsp; XX Jan-11 12000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AAA AAA7 Savannah&amp;nbsp; XX&amp;nbsp; Jan-11 80000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BBB BBB1 Yreka&amp;nbsp; XX Jan-11 1000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BBB BBB2 San Francisco&amp;nbsp; XX Jan-11 1000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BBB BBB3 Los Angeles&amp;nbsp; XX Jan-11 1000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BBB BBB4 Donalsonville&amp;nbsp; XX Jan-11 1000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BBB BBB5 Savannah&amp;nbsp; XX Jan-11 1000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select Company_Nm, Branch_Id, Product_Id, Date, Sales,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select mean(Sales) &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from have &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where Product_Id=a.Product_Id and date=a.date and not&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (Company_Nm = a.Company_Nm and Branch_Id = a.Branch_Id)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) as Competitor_Sale&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from have as a;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Aug 2015 18:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-the-same-procedure-for-all-observations/m-p/194956#M36666</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-08-08T18:49:43Z</dc:date>
    </item>
  </channel>
</rss>

