<?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 variable from 2 different proc statements with where condition for that variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339496#M272609</link>
    <description>&lt;P&gt;Why not just include them within one proc print? e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sort data=sashelp.class out=class;
  by sex;
run;
proc print data=class
   sumlabel='#byval(sex) Total'
   grandtotal_label='Grand Total';;
  title1 'whatever';
  title2 'etc.';
   sum weight;
  var name weight;
  by sex;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Mar 2017 01:24:04 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-03-09T01:24:04Z</dc:date>
    <item>
      <title>Sum of variable from 2 different proc statements with where condition for that variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339492#M272608</link>
      <description>&lt;P&gt;Hello all, excuse me if this is a silly or really easy question, because I am really new to SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 proc statements:&lt;/P&gt;&lt;PRE&gt;PROC PRINT DATA=WORK.IMPORT;
	WHERE DonColct="yes";
	
	TITLE1 'Earth Day Festival';
	TITLE3 'Sierra Club';
	TITLE4 'Apex High School Chapter';
	TITLE6 'Full Event Report';
	TITLE8 'Pledge Collected=yes';
	
	SUM donamt;
	
	VAR Sponsor donamt;
RUN;

PROC PRINT DATA=WORK.IMPORT;
	WHERE DonColct="no";
	
	TITLE1 'Earth Day Festival';
	TITLE3 'Sierra Club';
	TITLE4 'Apex High School Chapter';
	TITLE6 'Full Event Report';
	TITLE8 'Pledge Collected=no';
	
	SUM donamt;
	
	VAR Sponsor donamt;
RUN;&lt;/PRE&gt;&lt;P&gt;Inside the second proc statement, I want to add the sum of the donamt variable for all observations in the data set, not just when DonColct = "yes". How can this be done?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 01:10:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339492#M272608</guid>
      <dc:creator>NewbieToSAS</dc:creator>
      <dc:date>2017-03-09T01:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variable from 2 different proc statements with where condition for that variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339496#M272609</link>
      <description>&lt;P&gt;Why not just include them within one proc print? e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sort data=sashelp.class out=class;
  by sex;
run;
proc print data=class
   sumlabel='#byval(sex) Total'
   grandtotal_label='Grand Total';;
  title1 'whatever';
  title2 'etc.';
   sum weight;
  var name weight;
  by sex;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 01:24:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339496#M272609</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-09T01:24:04Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variable from 2 different proc statements with where condition for that variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339502#M272610</link>
      <description>&lt;P&gt;Actually, the thing is, I need 2 different tables as output, one with the data where DonColct="No" and the other where DonColct="Yes". The second table should have the sum of donamt for (where DonColct="No") and the overall sum of donamt just below it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second table should look like below. The first shaded box under "Donation Amount Pledged" is the total for donamt where DonColct="No" and the second shaded box under "Donation Amount Pledged" is the grand total of donamt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7630i1FA217A5EE57BBDB/image-size/original?v=1.0&amp;amp;px=-1" alt="Capture.PNG" title="Capture.PNG" border="0" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While the first table should look like (This works fine):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7631i72E00A01DCF86524/image-size/original?v=1.0&amp;amp;px=-1" alt="Capture.PNG" title="Capture.PNG" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 01:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339502#M272610</guid>
      <dc:creator>NewbieToSAS</dc:creator>
      <dc:date>2017-03-09T01:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variable from 2 different proc statements with where condition for that variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339503#M272611</link>
      <description>&lt;P&gt;Or, given you know in advance all the by levels, you can avoid sorting and writing the intemediate data set to disk.&amp;nbsp; Instead you could feed &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;'s proc print with a data set VIEW (not data set FILE) pre-sorted by sex.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data v_need/view=v_need;
  set sashelp.class (where=(sex='F'))
      sashelp.class (where=(sex='M')) ;
run;

proc print data=v_need    .... rest of Art's code here 
&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Mar 2017 01:39:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339503#M272611</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-09T01:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variable from 2 different proc statements with where condition for that variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339511#M272612</link>
      <description>&lt;P&gt;Thanks for the help guys, sorry to say I'm still facing a problem &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mkeintz, I tried merging your code with Art297's, however, it seems to produxe an error message at the log statement saying:&lt;/P&gt;&lt;PRE&gt; 75         sumlabel='#byval(DonColct) Total'
             ___
             180
 ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/PRE&gt;&lt;P&gt;This the assimilated form of the code I tried running as a standalone:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data v_need/view=v_need;
	set work.import (where=(DonColct='yes'))
		work.import (where=(DonColct='no')) ;
run;

proc print data=v_need;
	FORMAT donamt dollar11.2;
	
	sumlabel='#byval(DonColct) Total'
	grandtotal_label='Grand Total';;
	
	TITLE1 'Earth Day Festival';
	TITLE3 'Sierra Club';
	TITLE4 'Apex High School Chapter';
	TITLE6 'Full Event Report';
	TITLE8 'Pledge Collected=yes';
	SUM donamt;
	
	VAR Sponsor donamt;
	by DonColct;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can you please point out where I went wrong? Actually, I'm really new to SAS, so I've not actually familiar with some of the lines in this code (like, what is sumlabel and grandtotal_label?)&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 02:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339511#M272612</guid>
      <dc:creator>NewbieToSAS</dc:creator>
      <dc:date>2017-03-09T02:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variable from 2 different proc statements with where condition for that variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339517#M272613</link>
      <description>&lt;P&gt;Take another look at Art's code, and you'll see you inserted a premature semilcolon in the proc print statement, and also a complete format statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, note that in data set v_need, you put all the "Yes" records prior to all the "No" records.&amp;nbsp; But down in the proc print, the "by doncolct;" statement tells sas to expect them in ascending order.&amp;nbsp; (i.e. "No", then "Yes').&amp;nbsp; You can address this either by reordering the records in V_NEED, or modify the by statement to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by descending doncolct;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 03:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339517#M272613</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-09T03:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variable from 2 different proc statements with where condition for that variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339520#M272614</link>
      <description>&lt;P&gt;You also left one important semi-colon off. Try the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data v_need/view=v_need;
	set work.import (where=(DonColct='no'))
              work.import (where=(DonColct='yes')) ;
run;

proc print data=v_need;
	FORMAT donamt dollar11.2;
	
	sumlabel='#byval(DonColct) Total';
	grandtotal_label='Grand Total';
	
	TITLE1 'Earth Day Festival';
	TITLE3 'Sierra Club';
	TITLE4 'Apex High School Chapter';
	TITLE6 'Full Event Report';
	TITLE8 'Pledge Collected=yes';
	SUM donamt;
	
	VAR Sponsor donamt;
	by DonColct;
run;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 03:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339520#M272614</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-09T03:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variable from 2 different proc statements with where condition for that variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339539#M272615</link>
      <description>&lt;P&gt;Thanks so much for the help (and bearing with me) guys! I really appreciated it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;mkeintz, your advice was really helpful as I had no idea how the "sumlabel" and "grandtotal_label" worked. In fact, while I was editing my code, the one I posted in my previous solution, I was suspicious about the fact that they lost their blue color, which they originally had when I copied them fro Art297's post. I also fixed the final code for sorting it in descending order, that one missed my eye.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for informing me about the semicolon, Art297! I was like banging my head over it for like 15 minutes ;). Not to mention that the code you provided in the first place worked far better than my 2 proc statements combined.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've posted the final code here, it works now (phew), and it gives the desired output (double phew). Thanks again guys &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data v_need/view=v_need;
	set work.import (where=(DonColct='yes'))
		work.import (where=(DonColct='no')) ;
run;

proc print data=v_need NOOBS SPLIT=' '
	sumlabel='DonColct'
	grandtotal_label='';;
	
	LABEL 
		donamt='Donation Amount Pledged'
		Sponsor=' Sponsor Name'
		DonColct='Pledge Collected';
	
	FORMAT donamt dollar11.2;
	
	TITLE1 'Earth Day Festival';
	TITLE3 'Sierra Club';
	TITLE4 'Apex High School Chapter';
	TITLE6 'Full Event Report';

	SUM donamt;
	
	VAR Sponsor donamt;
	by DESCENDING DonColct;
	PAGEBY DonColct;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Mar 2017 04:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variable-from-2-different-proc-statements-with-where/m-p/339539#M272615</guid>
      <dc:creator>NewbieToSAS</dc:creator>
      <dc:date>2017-03-09T04:29:21Z</dc:date>
    </item>
  </channel>
</rss>

