<?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: Sum of Sum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-Sum/m-p/259186#M50092</link>
    <description>&lt;P&gt;It depends on the data, and possible the group by statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post some some sample data and the full code.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Mar 2016 22:13:13 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-03-25T22:13:13Z</dc:date>
    <item>
      <title>Sum of Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-Sum/m-p/259179#M50090</link>
      <description>&lt;P&gt;I have three separate proc sqls. In the first one I am selecting (sum(Rx)) as Sum_of_Rx. In the second proc sql, I select (sum(Sum_of_Rx)) as Sum_of_Sum_of_Rx. And in the third proc sql, I select (sum(Sum_of_Sum_of_Rx)) as Sum_of_sum_of_sum_of_Rx. If the value of Rx is 1, what will each of these sum variables be? Obviously the Sum_of_Rx would be 1, but what about the rest? Note: I didn't write this code. I'm trying to understand why the person who wrote it would do this.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 21:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-Sum/m-p/259179#M50090</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-03-25T21:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-Sum/m-p/259186#M50092</link>
      <description>&lt;P&gt;It depends on the data, and possible the group by statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post some some sample data and the full code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 22:13:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-Sum/m-p/259186#M50092</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-25T22:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-Sum/m-p/259188#M50094</link>
      <description>&lt;P&gt;Sum(Rx) is first defined in this datastep (earlier on Rx is set to value of 1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EGTASK.Data_Put_In_Access;
  set work.Calculated_Data2;
  format AffiliationID $6. ApprovedDispensingFeeAmount DOLLAR16.2 ApprovedPriceType $10. CarrierID $9. ClaimOriginationFlag $1.
		 ClaimStatus $1. CostTypeCode $10. DISPENSEASWRITTENDAWPRODUCTSELE $1.
		 ExtendedSupplyNetworkIndicator $1. FilledMonth $7. FilledQuarter $6.
		 GPINumber $14. MailOrderIndicator $1. MultiSourceCode $1. PlanDrugStatus $1.
		 PriceScheduleDefinition $10. RxNetworkID $6. RxNetworkID_CHAIN $6.
         SERVICEPROVIDERID $15. SuperPharmacyNetworkID $6. PHARMACYZIPCODE $10.
		 SUM_of_ApprovedIngredientCost DOLLAR16.2 SUM_of_ApprDispFeeAmount DOLLAR16.2 SUM_of_QUANTITYDISPENSED 13.3 ZIP $10.;
  RxNetworkID_CHAIN = RxNetworkID;
  SUM_of_ApprovedIngredientCost = sum(ApprovedIngredientCost);
  SUM_of_ApprDispFeeAmount = sum(ApprovedDispensingFeeAmount);
  SUM_of_AWP = sum(AWP);
  SUM_of_RX = sum(RX);
  SUM_of_QUANTITYDISPENSED = sum(QUANTITYDISPENSED);
  ZIP = PHARMACYZIPCODE;
  by AffiliationID ApprovedPriceType BRAND_GENERIC CarrierID ClaimOriginationFlag 
     ClaimStatus CLIENT CostTypeCode DISPENSEASWRITTENDAWPRODUCTSELE 
     ExtendedSupplyNetworkIndicator FilledMonth FilledQuarter FinalPlanCode GPINumber 
     MailOrderIndicator MultiSourceCode PlanDrugStatus PriceScheduleDefinition RxNetworkID 
     SERVICEPROVIDERID SuperPharmacyNetworkID PHARMACYZIPCODE Specialty_Flag EXCLUSIONS 
     IVLIndicator;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And here is the first proc sql where sum of the sum takes place:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL;&lt;BR /&gt; CREATE TABLE EGTASK.Data_Put_In_Access AS &lt;BR /&gt; SELECT t1.AccountID,&lt;BR /&gt;        t1.AffiliationID,&lt;BR /&gt;        t1.ApprovedIngredientCost, &lt;BR /&gt;        t1.ApprovedPriceType,&lt;BR /&gt;        t1.ApprovedDispensingFeeAmount,&lt;BR /&gt;        t1.AverageWholesalePriceUnitCost,&lt;BR /&gt;        t1.AWP, &lt;BR /&gt;        t1.BRAND_GENERIC, &lt;BR /&gt;        t1.CarrierID, &lt;BR /&gt;        t1.ClaimOriginationFlag, &lt;BR /&gt;        t1.ClaimStatus, &lt;BR /&gt;        t1.CLIENT,&lt;BR /&gt;        t1.COMPOUNDCODE, &lt;BR /&gt;        t1.CostTypeCode, &lt;BR /&gt;        t1.DISPENSEASWRITTENDAWPRODUCTSELE,&lt;BR /&gt;        t1.EXCLUSIONS,&lt;BR /&gt;        t1.ExtendedSupplyNetworkIndicator, &lt;BR /&gt;        t1.FilledMonth, &lt;BR /&gt;        t1.FilledQuarter, &lt;BR /&gt;        t1.FinalPlanCode, &lt;BR /&gt;        t1.GPINumber,&lt;BR /&gt;        t1.GroupPlanCode,&lt;BR /&gt;        t1.MailOrderIndicator,&lt;BR /&gt;        t1.MemberID, &lt;BR /&gt;        t1.MultiSourceCode,&lt;BR /&gt;        t1.NETWORK, &lt;BR /&gt;        t1.PlanDrugStatus, &lt;BR /&gt;        t1.PriceScheduleDefinition, &lt;BR /&gt;        t1.RxNetworkID, &lt;BR /&gt;        t1.RXNetworkID_CHAIN,&lt;BR /&gt;        t1.QUANTITYDISPENSED, &lt;BR /&gt;        t1.SERVICEPROVIDERID,&lt;BR /&gt;        t1.Specialty_Flag, &lt;BR /&gt;        t1.SuperPharmacyNetworkID, &lt;BR /&gt;        t1.ZIP,&lt;BR /&gt;        t1.SUM_of_ApprovedIngredientCost,&lt;BR /&gt;        t1.SUM_of_ApprDispFeeAmount,&lt;BR /&gt;       /* SUM_of_SUM_of_ApprovedIngredientCost */&lt;BR /&gt;       (SUM(t1.SUM_of_ApprovedIngredientCost)) AS SUM_of_SUM_of_AIC, &lt;BR /&gt;       /* SUM_of_SUM_of_AWP */&lt;BR /&gt;       (SUM(t1.SUM_of_AWP)) AS SUM_of_SUM_of_AWP, &lt;BR /&gt;       /* SUM_of_SUM_of_RX */&lt;BR /&gt;       (SUM(t1.SUM_of_RX)) AS SUM_of_SUM_of_RX, &lt;BR /&gt;       /* SUM_of_SUM_of_QUANTITYDISPENSED */&lt;BR /&gt;       (SUM(t1.SUM_of_QUANTITYDISPENSED)) FORMAT=13.3 AS SUM_of_SUM_of_QUANTITYDISPENSED,&lt;BR /&gt;       /* SUM_of_SUM_of_ApprDispFeeAmount */&lt;BR /&gt;       (SUM(t1.SUM_of_ApprDispFeeAmount)) AS SUM_of_SUM_of_ApprDispFeeAmount, &lt;BR /&gt;       t1.AFF_NAME, &lt;BR /&gt;       t1.AFF_TYPE, &lt;BR /&gt;       t1.NETWORK, &lt;BR /&gt;       t1.'Business Line'n, &lt;BR /&gt;       t1.'Analytics Grouping 1'n, &lt;BR /&gt;     FROM EGTASK.Data_Put_In_Access t1&lt;BR /&gt;     GROUP BY t1.AffiliationID, t1.ApprovedPriceType, t1.BRAND_GENERIC, t1.CarrierID, t1.ClaimOriginationFlag, &lt;BR /&gt;              t1.ClaimStatus, t1.CLIENT, t1.CostTypeCode, t1.DISPENSEASWRITTENDAWPRODUCTSELE, &lt;BR /&gt;              t1.ExtendedSupplyNetworkIndicator, t1.FilledMonth, t1.FilledQuarter, t1.FinalPlanCode, t1.GPINumber, &lt;BR /&gt;              t1.MailOrderIndicator, t1.MultiSourceCode, t1.PlanDrugStatus, t1.PriceScheduleDefinition, t1.RxNetworkID, &lt;BR /&gt;              t1.RXNetworkID_CHAIN, t1.SERVICEPROVIDERID, t1.SuperPharmacyNetworkID, t1.ZIP, t1.Specialty_Flag, &lt;BR /&gt;              t1.SUM_of_ApprovedIngredientCost, t1.AFF_NAME, t1.AFF_TYPE, t1.NETWORK, t1.'Business Line'n, t1.&lt;BR /&gt;              'Analytics Grouping 1'n, (CALCULATED 'MAC Savings Grouping'n), t1.IVLIndicator;&lt;BR /&gt;QUIT;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;And here is the second proc sql where the sum of sum of sum takes place:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE EGTASK.All_Combined_Table AS 
   SELECT t1.ApprovedDispensingFeeAmount,
          t1.ApprovedIngredientCost,
          t1.ApprovedPriceType,
          t1.AverageWholesalePriceUnitCost,
          t1.AWP,
          t1.BRAND_GENERIC,
          t1.CarrierID, 
          t1.CLIENT,
	  t1.ExtendedSupplyNetworkIndicator,
          t1.FilledMonth, 
          t1.FilledQuarter AS 'Filled Quarter'n, 
          t1.GPINumber, 
          t1.MailOrderIndicator,
          t1.MemberID, 
          t1.MultiSourceCode, 
          t1.PriceScheduleDefinition,
          t1.QUANTITYDISPENSED, 
          t1.RxNetworkID AS RXNetwork,
	  t1.RXNetworkID_CHAIN,
          t1.SuperPharmacyNetworkID, 
	  /* SUM_OF_ApprovedIngredientCost */
            (SUM(t1.SUM_of_SUM_of_AIC)) FORMAT=DOLLAR16.2 AS SUM_OF_ApprovedIngredientCost, 
          /* SUM_OF_AWP */
            (SUM(t1.SUM_of_SUM_of_AWP)) AS SUM_OF_SUM_OF_SUM_AWP, 
          /* SUM_OF_RX */
            (SUM(t1.SUM_of_SUM_of_RX)) AS SUM_OF_SUM_OF_SUM_RX, 
          /* SUM_OF_QUANTITYDISPENSED */
            (SUM(t1.SUM_of_SUM_of_QUANTITYDISPENSED)) FORMAT=13.3 AS SUM_OF_SUM_OF_SUM_QUANTITYDISPENSED,
	  /* SUM_OF_ADFA */
	    (SUM(t1.SUM_of_SUM_of_ApprDispFeeAmount)) FORMAT=DOLLAR16.2 AS SUM_OF_SUM_OF_SUM_ADFA,
          t1.AFF_NAME AS 'AFF Name'n, 
          t1.AFF_TYPE AS 'AFF Type'n, 
          t1.NETWORK,
          t1.Specialty_Flag, 
          t1.'Business Line'n AS Business_Line, 
          t1.'Analytics Grouping 1'n AS Analytics_Grouping1, 
          t1.'MAC Savings Grouping'n AS MACSavingsGrouping, 
          t1.IVLIndicator
      FROM EGTASK.DATA_WITH_MAC_GROUPING t1 LEFT JOIN EGTASK.Tables_for_SAS4 t2 ON (t1.PriceScheduleDefinition = t2.
          price_schedule)
      WHERE t1.NETWORK NOT = 'PAPERMATCH'
      GROUP BY t1.ApprovedPriceType, t1.CarrierID, t1.CLIENT, t1.FilledMonth, t1.FilledQuarter, t1.GPINumber, 
              t1.MailOrderIndicator, t1.MultiSourceCode, t1.PriceScheduleDefinition, t1.RxNetworkID, 
              t1.SuperPharmacyNetworkID, t1.AFF_NAME, t1.AFF_TYPE, t1.NETWORK, t1.'Business Line'n, t1.
              'Analytics Grouping 1'n, t1.'MAC Savings Grouping'n, (CALCULATED 'MAC List'n), t1.IVLIndicator;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 22:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-Sum/m-p/259188#M50094</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-03-25T22:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-Sum/m-p/259191#M50097</link>
      <description>&lt;P&gt;Love the naming conventions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first sum in the data step doesn't do anything, it only renames the variable and is pretty useless as shown.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second sum creates an aggregate across the group by variables&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the third creates another aggregate across a different set of group by variables, after joining with a different table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example, total by county for first SQL and then by state.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If if its set to 1 initially it could be used as a record counter to determine how many records are in each group by component.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 22:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-Sum/m-p/259191#M50097</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-25T22:53:15Z</dc:date>
    </item>
  </channel>
</rss>

