<?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: SAS macro for adding sales figures from different monthly datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157421#M30719</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I get the error report: "A character operand was found in the%EVAL function.... where a numeric operand is required. ..."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some values have decimals...any solution please?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 24 Sep 2014 14:36:03 GMT</pubDate>
    <dc:creator>Xray</dc:creator>
    <dc:date>2014-09-24T14:36:03Z</dc:date>
    <item>
      <title>SAS macro for adding sales figures from different monthly datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157416#M30714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have several seasonal datasets with the same variables for the same divisions - e.g. Month1 dataset has a column called 'sales' for each divisionXi.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need a SAS macro to add, say, all monthly sales for each division to get a year's total without merging the monthly datasets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each dataset looks like this;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dataset Mi&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Division Sales Profit Salary ...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone who can help with a macro to create a yearly dataset summing monthly figures?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ray&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Sep 2014 07:07:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157416#M30714</guid>
      <dc:creator>Xray</dc:creator>
      <dc:date>2014-09-24T07:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro for adding sales figures from different monthly datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157417#M30715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data month1;&lt;BR /&gt;input Division Sales Profit Salary;&lt;BR /&gt;datalines;&lt;BR /&gt;1 200 10 90&lt;BR /&gt;2 300 20 50&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data month2;&lt;BR /&gt;input Division Sales Profit Salary;&lt;BR /&gt;datalines;&lt;BR /&gt;1 300 10 90&lt;BR /&gt;2 400 20 50&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;%macro sums(tbl);&lt;/P&gt;&lt;P&gt;%let i=1;&lt;BR /&gt;%let salesall=0;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%do %until (%scan(&amp;amp;tbl, &amp;amp;i)=);&lt;/P&gt;&lt;P&gt;%let mnno=%scan(&amp;amp;tbl, &amp;amp;i);&lt;BR /&gt;proc sql;&lt;BR /&gt;select sum(sales) into :summonth&amp;amp;i from &amp;amp;mnno;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%let i=%eval(&amp;amp;i+1);&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%do j=1 %to %eval(&amp;amp;i-1);&lt;BR /&gt;%let salesall=%eval(&amp;amp;salesall+&amp;amp;&amp;amp;summonth&amp;amp;j);&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%put Total sales = &amp;amp;salesall;&lt;/P&gt;&lt;P&gt;%mend sums;&lt;/P&gt;&lt;P&gt;%sums(month1 month2)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Sep 2014 07:57:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157417#M30715</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-09-24T07:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro for adding sales figures from different monthly datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157418#M30716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or, alternatively do it in straight code, no macros/variables (note that I prefer to put results into a dataset, this helps further processing so you could easily change the select into):&lt;/P&gt;&lt;P&gt;data month1;&lt;BR /&gt;&amp;nbsp; input Division Sales Profit Salary;&lt;BR /&gt;datalines;&lt;BR /&gt;1 200 10 90&lt;BR /&gt;2 300 20 50&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data month2;&lt;BR /&gt;&amp;nbsp; input Division Sales Profit Salary;&lt;BR /&gt;datalines;&lt;BR /&gt;1 300 10 90&lt;BR /&gt;2 400 20 50&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table RESULTS &lt;BR /&gt;&amp;nbsp; (&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MONTH num,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TOTAL_SALES num&lt;BR /&gt;&amp;nbsp; );&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; set sashelp.vtable (where=(libname="WORK" and substr(memname,1,5)="MONTH"));&lt;BR /&gt;&amp;nbsp; call execute('proc sql;&lt;BR /&gt;&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; insert into RESULTS&lt;BR /&gt;&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; set MONTH='||strip(tranwrd(memname,"MONTH",""))||',&lt;BR /&gt;&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; TOTAL_SALES=(select sum(SALES) from '||strip(memname)||');&lt;BR /&gt;&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; quit;');&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;&amp;nbsp; select&amp;nbsp; sum(TOTAL_SALES)&lt;BR /&gt;&amp;nbsp; into&amp;nbsp;&amp;nbsp;&amp;nbsp; :SALESALL&lt;BR /&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; RESULTS;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;SALESALL.;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Sep 2014 08:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157418#M30716</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-09-24T08:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro for adding sales figures from different monthly datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157419#M30717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;May I request you to explain the below line from your code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%do %until (%scan(&amp;amp;tbl, &amp;amp;i)=);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;If I'm not wrong, &amp;amp;tbl will resolves to 'month' when i=1. So your code will convert to &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%do %until (%scan(month1, 1)=);&amp;nbsp; We don't have any variable called 'month1' in both the tables instead it's a table.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Sep 2014 13:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157419#M30717</guid>
      <dc:creator>RamKumar</dc:creator>
      <dc:date>2014-09-24T13:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro for adding sales figures from different monthly datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157420#M30718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the loop is used to read &amp;amp;tbl macro variable which when calling the macro is &lt;EM&gt;month1 month2.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when i=1 the result of (%scan(&amp;amp;tbl, &amp;amp;i) will resolve to &lt;EM&gt;month1.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;You can use macro options - symbolgen, mprint , mlogic to check how the macro works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code should be used under my assumption that data looks as per the 2 data sets (month1 and month2) provided before the macro.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Sep 2014 13:52:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157420#M30718</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-09-24T13:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro for adding sales figures from different monthly datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157421#M30719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I get the error report: "A character operand was found in the%EVAL function.... where a numeric operand is required. ..."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some values have decimals...any solution please?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Sep 2014 14:36:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157421#M30719</guid>
      <dc:creator>Xray</dc:creator>
      <dc:date>2014-09-24T14:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro for adding sales figures from different monthly datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157422#M30720</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not append the datasets? Is it because the data is too big?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would create a view and then run a proc means on the data myself.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Sep 2014 14:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-for-adding-sales-figures-from-different-monthly/m-p/157422#M30720</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-09-24T14:44:45Z</dc:date>
    </item>
  </channel>
</rss>

