<?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: Column totals in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/257704#M49505</link>
    <description>&lt;P&gt;Okay. so I have a new variation of things, with slight differences:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=EGTASK.FL_MULTIPLIER_SAVINGS_2015;
  where Business_Line = 'Commercial' and Channel = 'Retail' and CLIENT = 'FL' and NETWORK = 'FL INSTATE' and Specialty_Flag = 'Non-Specialty' and BRAND_GENERIC = 'Generic' and index(ApprovedPriceType,'MAC') &amp;gt; 0;
  id Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;
  var ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;
  output out=Total_Savings_FL&lt;FONT color="#FF0000"&gt;v5&lt;/FONT&gt;_2015_3(drop=_:)
         sum(ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX)=ING_15 DF_15 RX_15
         mean(AWP_Rate ApprovedDispensingFeeAmount)=Avg_AWP_Rate_15 Avg_ADFA_15;
run;

proc summary data=EGTASK.FL_MULTIPLIER_SAVINGS_2015;
  where Business_Line = 'Commercial' and Channel = 'Retail' and CLIENT = 'FL' and NETWORK = 'FL INSTATE' and Specialty_Flag = 'Specialty' and BRAND_GENERIC = 'Generic' and index(ApprovedPriceType,'MAC') &amp;gt; 0;
  id Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;
  var ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;
  output out=Total_Savings_FL&lt;FONT color="#FF0000"&gt;v5&lt;/FONT&gt;_2015_6(drop=_:)
         sum(ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX)=ING_15 DF_15 RX_15
         mean(AWP_Rate ApprovedDispensingFeeAmount)=Avg_AWP_Rate_15 Avg_ADFA_15;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've attempted to write a macro for these two and it looks like this (the main new change is that the output dataset name now has an "infix", i.e. "v5"), so I added a macro variable called infix:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro summ(yr=, crit=, infix=, suffix=);
proc summary data=EGTASK.FL_MULTIPLIER_SAVINGS_20&amp;amp;yr;
  where Business_Line = 'Commercial' and Channel = 'Retail' and CLIENT = 'FL' and NETWORK = 'FL INSTATE' and BRAND_GENERIC = 'Generic' and index(ApprovedPriceType,'MAC') &amp;gt; 0 and &amp;amp;crit;
  id Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;
  var ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;
  output out=Total_Savings_FL&amp;amp;infix_20&amp;amp;yr.&amp;amp;suffix(drop=_:)
         sum(ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX)=ING_&amp;amp;yr DF_&amp;amp;yr RX_&amp;amp;yr
         mean(AWP_Rate ApprovedDispensingFeeAmount)=Avg_AWP_Rate_&amp;amp;yr Avg_ADFA_&amp;amp;yr;
run;
%mend summ;

%summ(yr=15, crit=Specialty_Flag = 'Non-Specialty', infix=v5)
%summ(yr=15, crit=Specialty_Flag = 'Specialty', infix=v5, suffix=_2)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, when I run it, I get an error on the &amp;amp;infix statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;   var ApprovedIngredientCost
38       ! SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;   output out=Total_Savings_FL&amp;amp;infix_20&amp;amp;yr.&amp;amp;suffix(drop=_:)
                                                                                                    _
                                                                                                    22
38       !        sum
&lt;FONT color="#FF0000"&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, (, /, CSS, CV, IDGROUP, IDGRP, KURTOSIS, LCLM, MAX, MAXID, MEAN, 
              MEDIAN, MIN, MINID, MODE, N, NMISS, OUT, P1, P10, P20, P25, P30, P40, P5, P50, P60, P70, P75, P80, P90, P95, P99, 
              PROBT, Q1, Q3, QRANGE, RANGE, SKEWNESS, STDDEV, STDERR, SUM, SUMWGT, T, UCLM, USS, VAR. &lt;/FONT&gt; 

NOTE: Line generated by the invoked macro "SUMM".
38          Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;   var ApprovedIngredientCost
38       ! SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;   output out=Total_Savings_FL&amp;amp;infix_20&amp;amp;yr.&amp;amp;suffix(drop=_:)
                                                                                                    _
                                                                                                    76
38       !        sum
&lt;FONT color="#FF0000"&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My guess is that I'm missing something simple here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;JediApprentice&lt;/P&gt;</description>
    <pubDate>Fri, 18 Mar 2016 21:13:03 GMT</pubDate>
    <dc:creator>JediApprentice</dc:creator>
    <dc:date>2016-03-18T21:13:03Z</dc:date>
    <item>
      <title>Column totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/255309#M48751</link>
      <description>&lt;P&gt;I am attempting to create column totals for a few variables in a dataset. I want to store these totals in separate&amp;nbsp;variables so I can use them in a new data step. I understand proc print has a sum statement that computes the total, but it doesn't store that total in a variable.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2016 17:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/255309#M48751</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-03-08T17:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: Column totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/255315#M48752</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/73936"&gt;@JediApprentice﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/68954/HTML/default/viewer.htm#p0aq3hsvflztfzn1xa2wt6s35oy6.htm" target="_blank"&gt;PROC SUMMARY&lt;/A&gt; is&amp;nbsp;more suitable for this purpose than PROC PRINT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=sashelp.class;
var age weight height;
output out=totals sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above step computes the totals of variables AGE, WEIGHT and HEIGHT (as listed in the VAR statement) across all observations in dataset SASHELP.CLASS and stores the results in variables of the same names in a dataset which I named TOTALS (see OUTPUT statement). The totals are requested by the SUM= option of the OUTPUT statement. (After the equals sign you could specify different variable names for the totals, if desired, e.g.,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;sum=tot_age tot_wgt tot_hgt&lt;/FONT&gt;.)&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2016 18:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/255315#M48752</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-08T18:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Column totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/255329#M48755</link>
      <description>&lt;P&gt;Thank you, this was very helpful. I have one more question going off of this. Take a look at my code:&lt;/P&gt;&lt;PRE&gt;data Total_Savings_2015_prep;
  set EGTASK.FL_INSTATE_SAVINGS_2015;
  if SPECIALTY = 'N' and BRAND_GENERIC = 'Brand' and ApprovedPriceType = 'AWP';
run;

proc summary data=Total_Savings_2015_prep;
  var SUM_OF_APPROVEDINGREDIENTCOST SUM_OF_ADFA SUM_OF_RX;
  output out=totals_sum_2015 sum=ING DF RX;
run;

proc summary data=Total_Savings_2015_prep;
  var AWP_Rate ApprovedDispensingFeeAmount;
  output out=totals_mean_2015 mean=Avg_AWP_Rate Avg_ADFA;
run;

data Total_Savings_2015;
  set totals_sum_2015; 
  set totals_mean_2015;
run;&lt;/PRE&gt;&lt;P&gt;You'll notice in the first data step, I am subsetting for certain values of different variables. I would like these variables to show up in the final dataset so that my output would look something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SPECIALTY&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BRAND_GENERIC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ApprovedPriceType&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color="#0000ff"&gt; ING&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DF&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Avg_AWP_Rate&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Avg_ADFA&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; N&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; Brand&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; AWP&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;FONT color="#0000ff"&gt;$48,923&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $2.00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;32&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; 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; $2.00&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;The data in blue is what I already have in that last dataset.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2016 19:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/255329#M48755</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-03-08T19:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: Column totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/255352#M48758</link>
      <description>&lt;P&gt;You're welcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could create Total_Savings_2015 (incl. the desired additional variables) in one step from&amp;nbsp;EGTASK.FL_INSTATE_SAVINGS_2015:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=EGTASK.FL_INSTATE_SAVINGS_2015;
  where SPECIALTY = 'N' and BRAND_GENERIC = 'Brand' and ApprovedPriceType = 'AWP';
  id SPECIALTY BRAND_GENERIC ApprovedPriceType;
  var SUM_OF_APPROVEDINGREDIENTCOST SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;
  output out=Total_Savings_2015(drop=_:)
         sum(SUM_OF_APPROVEDINGREDIENTCOST SUM_OF_ADFA SUM_OF_RX)=ING DF RX
         mean(AWP_Rate ApprovedDispensingFeeAmount)=Avg_AWP_Rate Avg_ADFA;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The WHERE statement restricts the summary statistics to the subset of observations which you called Total_Savings_2015_prep. The ID statement brings in the additional variables (actually the "maximum values" of these, but this is necessarily the single combination selected by the WHERE statement). The VAR statement lists all analysis variables. They are assigned to the two different statistics in the OUTPUT statement. Finally, the DROP= dataset option drops&amp;nbsp;all variables whose names start with an underscore, i.e. the two default variables _TYPE_ and _FREQ_, from the output dataset (assuming you don't need them).&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2016 20:08:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/255352#M48758</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-08T20:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: Column totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/257621#M49465</link>
      <description>&lt;P&gt;Say I have multiple proc summaries with different criteria in the where statement to compute, like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=EGTASK.FL_INSTATE_SAVINGS_2015;
  where Business_Line = 'Commercial' and Channel = 'Retail' and CLIENT = 'FL' and NETWORK = 'FL INSTATE' and Specialty_Flag = 'Non-Specialty' and BRAND_GENERIC = 'Brand' and ApprovedPriceType = 'AWP';
  id Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;
  var ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;
  output out=Total_Savings_FL_2015(drop=_:)
         sum(ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX)=ING_15 DF_15 RX_15
         mean(AWP_Rate ApprovedDispensingFeeAmount)=Avg_AWP_Rate_15 Avg_ADFA_15;
run;

proc summary data=EGTASK.FL_INSTATE_SAVINGS_2015;
  where Business_Line = 'Commercial' and Channel = 'Retail' and CLIENT = 'FL' and NETWORK = 'FL INSTATE' and Specialty_Flag = 'Non-Specialty' and BRAND_GENERIC = 'Generic' and ApprovedPriceType = 'AWP';
  id Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;
  var ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;
  output out=Total_Savings_FL_2015_2(drop=_:)
         sum(ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX)=ING_15 DF_15 RX_15
         mean(AWP_Rate ApprovedDispensingFeeAmount)=Avg_AWP_Rate_15 Avg_ADFA_15;
run;

proc summary data=EGTASK.FL_INSTATE_SAVINGS_2015;
  where Business_Line = 'Commercial' and Channel = 'Retail' and CLIENT = 'FL' and NETWORK = 'FL INSTATE' and Specialty_Flag = 'Non-Specialty' and BRAND_GENERIC = 'Generic' and index(ApprovedPriceType,'MAC') &amp;gt; 0;
  id Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;
  var ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;
  output out=Total_Savings_FL_2015_3(drop=_:)
         sum(ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX)=ING_15 DF_15 RX_15
         mean(AWP_Rate ApprovedDispensingFeeAmount)=Avg_AWP_Rate_15 Avg_ADFA_15;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Would there be a more efficient way to cycle through the different cases (such as using a macro or a loop)?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 14:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/257621#M49465</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-03-18T14:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: Column totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/257643#M49473</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/73936"&gt;@JediApprentice﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, sure. You could use a macro to make the varying parts of the program code flexible. I'd suggest to make also the year flexible (so you can reuse the code until 2099 :-)).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro summ(yr=, crit=, suffix=);
proc summary data=EGTASK.FL_INSTATE_SAVINGS_20&amp;amp;yr;
  where Business_Line = 'Commercial' and Channel = 'Retail' and CLIENT = 'FL' and NETWORK = 'FL INSTATE' and Specialty_Flag = 'Non-Specialty' and &amp;amp;crit;
  id Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;
  var ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;
  output out=Total_Savings_FL_20&amp;amp;yr.&amp;amp;suffix(drop=_:)
         sum(ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX)=ING_&amp;amp;yr DF_&amp;amp;yr RX_&amp;amp;yr
         mean(AWP_Rate ApprovedDispensingFeeAmount)=Avg_AWP_Rate_&amp;amp;yr Avg_ADFA_&amp;amp;yr;
run;
%mend summ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To execute the original three PROC SUMMARY steps, you just call the macro with the appropriate parameters:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%summ(yr=15, crit=BRAND_GENERIC = 'Brand' and ApprovedPriceType = 'AWP')
%summ(yr=15, crit=BRAND_GENERIC = 'Generic' and ApprovedPriceType = 'AWP', suffix=_2)
%summ(yr=15, crit=BRAND_GENERIC = 'Generic' and index(ApprovedPriceType,'MAC'), suffix=_3)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first macro call doesn't specify parameter SUFFIX. As no default value for this parameter has been defined, nothing is appended to the output dataset name (as desired).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the third macro call I have removed the "&amp;gt; 0" just for abbreviation, because it is redundant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For debugging purposes you can use system option &lt;A href="http://support.sas.com/documentation/cdl/en/syntaxidx/68719/HTML/default/index.htm#/documentation/cdl/en/mcrolref/67912/HTML/default/p1dhqw0i5yj2m8n15opapnwteqra.htm" target="_blank"&gt;MPRINT&lt;/A&gt; to see the program code generated by a macro call in the log.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 15:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/257643#M49473</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-18T15:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Column totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/257644#M49474</link>
      <description>&lt;P&gt;Thank you, much appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 15:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/257644#M49474</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-03-18T15:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Column totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/257704#M49505</link>
      <description>&lt;P&gt;Okay. so I have a new variation of things, with slight differences:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=EGTASK.FL_MULTIPLIER_SAVINGS_2015;
  where Business_Line = 'Commercial' and Channel = 'Retail' and CLIENT = 'FL' and NETWORK = 'FL INSTATE' and Specialty_Flag = 'Non-Specialty' and BRAND_GENERIC = 'Generic' and index(ApprovedPriceType,'MAC') &amp;gt; 0;
  id Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;
  var ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;
  output out=Total_Savings_FL&lt;FONT color="#FF0000"&gt;v5&lt;/FONT&gt;_2015_3(drop=_:)
         sum(ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX)=ING_15 DF_15 RX_15
         mean(AWP_Rate ApprovedDispensingFeeAmount)=Avg_AWP_Rate_15 Avg_ADFA_15;
run;

proc summary data=EGTASK.FL_MULTIPLIER_SAVINGS_2015;
  where Business_Line = 'Commercial' and Channel = 'Retail' and CLIENT = 'FL' and NETWORK = 'FL INSTATE' and Specialty_Flag = 'Specialty' and BRAND_GENERIC = 'Generic' and index(ApprovedPriceType,'MAC') &amp;gt; 0;
  id Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;
  var ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;
  output out=Total_Savings_FL&lt;FONT color="#FF0000"&gt;v5&lt;/FONT&gt;_2015_6(drop=_:)
         sum(ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX)=ING_15 DF_15 RX_15
         mean(AWP_Rate ApprovedDispensingFeeAmount)=Avg_AWP_Rate_15 Avg_ADFA_15;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've attempted to write a macro for these two and it looks like this (the main new change is that the output dataset name now has an "infix", i.e. "v5"), so I added a macro variable called infix:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro summ(yr=, crit=, infix=, suffix=);
proc summary data=EGTASK.FL_MULTIPLIER_SAVINGS_20&amp;amp;yr;
  where Business_Line = 'Commercial' and Channel = 'Retail' and CLIENT = 'FL' and NETWORK = 'FL INSTATE' and BRAND_GENERIC = 'Generic' and index(ApprovedPriceType,'MAC') &amp;gt; 0 and &amp;amp;crit;
  id Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;
  var ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;
  output out=Total_Savings_FL&amp;amp;infix_20&amp;amp;yr.&amp;amp;suffix(drop=_:)
         sum(ApprovedIngredientCost SUM_OF_ADFA SUM_OF_RX)=ING_&amp;amp;yr DF_&amp;amp;yr RX_&amp;amp;yr
         mean(AWP_Rate ApprovedDispensingFeeAmount)=Avg_AWP_Rate_&amp;amp;yr Avg_ADFA_&amp;amp;yr;
run;
%mend summ;

%summ(yr=15, crit=Specialty_Flag = 'Non-Specialty', infix=v5)
%summ(yr=15, crit=Specialty_Flag = 'Specialty', infix=v5, suffix=_2)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, when I run it, I get an error on the &amp;amp;infix statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;   var ApprovedIngredientCost
38       ! SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;   output out=Total_Savings_FL&amp;amp;infix_20&amp;amp;yr.&amp;amp;suffix(drop=_:)
                                                                                                    _
                                                                                                    22
38       !        sum
&lt;FONT color="#FF0000"&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, (, /, CSS, CV, IDGROUP, IDGRP, KURTOSIS, LCLM, MAX, MAXID, MEAN, 
              MEDIAN, MIN, MINID, MODE, N, NMISS, OUT, P1, P10, P20, P25, P30, P40, P5, P50, P60, P70, P75, P80, P90, P95, P99, 
              PROBT, Q1, Q3, QRANGE, RANGE, SKEWNESS, STDDEV, STDERR, SUM, SUMWGT, T, UCLM, USS, VAR. &lt;/FONT&gt; 

NOTE: Line generated by the invoked macro "SUMM".
38          Business_Line Channel CLIENT NETWORK Specialty_Flag BRAND_GENERIC ApprovedPriceType;   var ApprovedIngredientCost
38       ! SUM_OF_ADFA SUM_OF_RX AWP_Rate ApprovedDispensingFeeAmount;   output out=Total_Savings_FL&amp;amp;infix_20&amp;amp;yr.&amp;amp;suffix(drop=_:)
                                                                                                    _
                                                                                                    76
38       !        sum
&lt;FONT color="#FF0000"&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My guess is that I'm missing something simple here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;JediApprentice&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 21:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/257704#M49505</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-03-18T21:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Column totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/257709#M49509</link>
      <description>&lt;P&gt;Yes, indeed: Just insert a period after &lt;FONT face="courier new,courier"&gt;&amp;amp;infix&lt;/FONT&gt;. This is to indicate the end of the macro variable reference. Otherwise, SAS will try to resolve a macro variable reference &lt;FONT face="courier new,courier"&gt;&amp;amp;infix_20&lt;/FONT&gt;. The name &lt;FONT face="courier new,courier"&gt;infix_20&lt;/FONT&gt; is a valid macro variable name, but a macro variable of this name&amp;nbsp;does not exist, hence the errors.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 21:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Column-totals/m-p/257709#M49509</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-18T21:36:11Z</dc:date>
    </item>
  </channel>
</rss>

