<?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 Conditional Loops / Aggregation of Data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Loops-Aggregation-of-Data/m-p/617093#M180767</link>
    <description>&lt;P&gt;Hello! I'm trying to extract sum information from a relatively big dataset I'm working with. At this point, I have information about thousands of companies identified by CUSIP (a unique identifier), prices and quantity data and corresponding dates. Here is what I want to do:&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to write a loop (perfect if a loop is not necessary indeed) that selects a specific company (by CUSIP) and produce a value weighted number (Price*Quantity)/(Sum(Quantity| for a specific date) such that for example according to the image below, row 1-7 is replaced by a single row containing the aggregated data (CUSIP and date remain the same). I do not know where to start and any hints would be very much appreciated. FYI, I studied how loops work in SAS, but I do not know how to write a loop that at each step selects a CUSIP for a specific Execution_date and performs the aggregation, saves it and moves to the second CUSIP-date combination.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2020-01-13 at 7.05.07 PM.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35314i116435D40155C279/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2020-01-13 at 7.05.07 PM.png" alt="Screen Shot 2020-01-13 at 7.05.07 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jan 2020 00:18:29 GMT</pubDate>
    <dc:creator>ali11</dc:creator>
    <dc:date>2020-01-14T00:18:29Z</dc:date>
    <item>
      <title>Conditional Loops / Aggregation of Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Loops-Aggregation-of-Data/m-p/617093#M180767</link>
      <description>&lt;P&gt;Hello! I'm trying to extract sum information from a relatively big dataset I'm working with. At this point, I have information about thousands of companies identified by CUSIP (a unique identifier), prices and quantity data and corresponding dates. Here is what I want to do:&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to write a loop (perfect if a loop is not necessary indeed) that selects a specific company (by CUSIP) and produce a value weighted number (Price*Quantity)/(Sum(Quantity| for a specific date) such that for example according to the image below, row 1-7 is replaced by a single row containing the aggregated data (CUSIP and date remain the same). I do not know where to start and any hints would be very much appreciated. FYI, I studied how loops work in SAS, but I do not know how to write a loop that at each step selects a CUSIP for a specific Execution_date and performs the aggregation, saves it and moves to the second CUSIP-date combination.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2020-01-13 at 7.05.07 PM.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35314i116435D40155C279/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2020-01-13 at 7.05.07 PM.png" alt="Screen Shot 2020-01-13 at 7.05.07 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 00:18:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Loops-Aggregation-of-Data/m-p/617093#M180767</guid>
      <dc:creator>ali11</dc:creator>
      <dc:date>2020-01-14T00:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Loops / Aggregation of Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Loops-Aggregation-of-Data/m-p/617098#M180770</link>
      <description>&lt;P&gt;What you are describing is a weighted avereage. This is done via PROC SUMMARY, no looping neeed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
     class cusip_id execution_date;
     var price/weight=quantity;
     output out=aggregation mean=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suggestion: since you are using SAS, which is one of the leading statistical analysis available, if not the leading statistical package available, please know that an extremely large number of analyses have been built into SAS, including summing and computing means. Before you come to the conclusion that you will have to program some loops somehow to do this, please save yourself some time and ask/investigate if it has already been programmed.&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 14 Jan 2020 01:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Loops-Aggregation-of-Data/m-p/617098#M180770</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-14T01:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Loops / Aggregation of Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Loops-Aggregation-of-Data/m-p/617231#M180823</link>
      <description>thanks. very helpful and just what I needed.</description>
      <pubDate>Tue, 14 Jan 2020 16:00:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Loops-Aggregation-of-Data/m-p/617231#M180823</guid>
      <dc:creator>ali11</dc:creator>
      <dc:date>2020-01-14T16:00:22Z</dc:date>
    </item>
  </channel>
</rss>

