<?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: Add individual fields summarized by a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-individual-fields-summarized-by-a-macro-variable/m-p/712281#M219577</link>
    <description>that's just it, the variables are not constant, the list is ever changing (or rather is a series of all possible combinations).  For example:&lt;BR /&gt;&lt;BR /&gt;%Let weightvar = MATERIALS LABOR VOH FOH GNA INTEREST;&lt;BR /&gt;%Let weightvar =                     LABOR VOH FOH GNA INTEREST;&lt;BR /&gt;%Let weightvar =                                  VOH FOH GNA INTEREST;&lt;BR /&gt;%Let weightvar = MATERIALS              VOH FOH GNA INTEREST;&lt;BR /&gt;%Let weightvar = MATERIALS              VOH         GNA INTEREST;&lt;BR /&gt;&lt;BR /&gt;etc....&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 19 Jan 2021 00:58:14 GMT</pubDate>
    <dc:creator>texasmfp</dc:creator>
    <dc:date>2021-01-19T00:58:14Z</dc:date>
    <item>
      <title>Add individual fields summarized by a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-individual-fields-summarized-by-a-macro-variable/m-p/712274#M219570</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to automate a task. I create a macro variable as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%Let weightvar = MATERIALS LABOR VOH FOH GNA INTEREST;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MATERIALS LABOR VOH FOH GNA INTEREST&amp;nbsp;are field names in a database.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I weight average these in a PROC MEANS step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Later, in a data step, I want to add these variables together to form a new field TOTALCOST.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I want to run the prog multiple times, each time adding or subtracting one or more of the fields in the weightvar line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously, TOTALCOST=sum(&amp;amp;weightvar); does not work.&amp;nbsp; What are some options to effect this?&amp;nbsp; Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 00:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-individual-fields-summarized-by-a-macro-variable/m-p/712274#M219570</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2021-01-19T00:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Add individual fields summarized by a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-individual-fields-summarized-by-a-macro-variable/m-p/712276#M219572</link>
      <description>&lt;P&gt;Not sure if I understand, but are you able to share the code? If the variables will remain constant, you can always you:&lt;/P&gt;&lt;P&gt;TotalCost = SUM(&lt;SPAN&gt;MATERIALS,LABOR,VOH,FOH,GNA,INTEREST) *Separated by commas;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If you want to execute them conditionally, such as adding or subtracting the variables, wrap it in a macro and use %IF statements to generate SAS code.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 00:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-individual-fields-summarized-by-a-macro-variable/m-p/712276#M219572</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-01-19T00:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Add individual fields summarized by a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-individual-fields-summarized-by-a-macro-variable/m-p/712277#M219573</link>
      <description>&lt;P&gt;Use the TRANSLATE function to add commas.&lt;/P&gt;
&lt;P&gt;You could either create a second macro variable at the top of your program or use it inline in your code as desired.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro addCommas(varList=);
%sysfunc(translate(&amp;amp;varList, %str(, ), %str( )))
%mend addCommas;

%let comma_delimited_list = %addCommas(varList = MATERIALS LABOR VOH FOH GNA INTEREST);

%put &amp;amp;comma_delimited_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could use it directly inline with your code if you wanted, something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sumVariables = sum(%addCommas(varList = &amp;amp;weightVar.));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jan 2021 00:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-individual-fields-summarized-by-a-macro-variable/m-p/712277#M219573</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-01-19T00:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: Add individual fields summarized by a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-individual-fields-summarized-by-a-macro-variable/m-p/712278#M219574</link>
      <description>And if you were doing this for various different variable combinations I would assume you were using some of the combinatorial functions in SAS along with CALL EXECUTE(). You could just create two macro variables within that step one that was comma delimited and one that was space delimited to pass to the macro. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Jan 2021 00:43:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-individual-fields-summarized-by-a-macro-variable/m-p/712278#M219574</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-01-19T00:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: Add individual fields summarized by a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-individual-fields-summarized-by-a-macro-variable/m-p/712279#M219575</link>
      <description>Yes, to test lots of combinations, I intend to automate using a series of call execute</description>
      <pubDate>Tue, 19 Jan 2021 00:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-individual-fields-summarized-by-a-macro-variable/m-p/712279#M219575</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2021-01-19T00:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Add individual fields summarized by a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-individual-fields-summarized-by-a-macro-variable/m-p/712281#M219577</link>
      <description>that's just it, the variables are not constant, the list is ever changing (or rather is a series of all possible combinations).  For example:&lt;BR /&gt;&lt;BR /&gt;%Let weightvar = MATERIALS LABOR VOH FOH GNA INTEREST;&lt;BR /&gt;%Let weightvar =                     LABOR VOH FOH GNA INTEREST;&lt;BR /&gt;%Let weightvar =                                  VOH FOH GNA INTEREST;&lt;BR /&gt;%Let weightvar = MATERIALS              VOH FOH GNA INTEREST;&lt;BR /&gt;%Let weightvar = MATERIALS              VOH         GNA INTEREST;&lt;BR /&gt;&lt;BR /&gt;etc....&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Jan 2021 00:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-individual-fields-summarized-by-a-macro-variable/m-p/712281#M219577</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2021-01-19T00:58:14Z</dc:date>
    </item>
  </channel>
</rss>

