<?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: creating sum variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/creating-sum-variables/m-p/199313#M49823</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hope this is what you are expecting&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data XY;&lt;/P&gt;&lt;P&gt;input x y;&lt;/P&gt;&lt;P&gt;ord=1;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;18 23&lt;/P&gt;&lt;P&gt;13 20&lt;/P&gt;&lt;P&gt;18 18&lt;/P&gt;&lt;P&gt;15 16&lt;/P&gt;&lt;P&gt;10 14&lt;/P&gt;&lt;P&gt;12 11&lt;/P&gt;&lt;P&gt;8 10&lt;/P&gt;&lt;P&gt;4 7&lt;/P&gt;&lt;P&gt;7 6&lt;/P&gt;&lt;P&gt;3 4&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=xy;&lt;/P&gt;&lt;P&gt;by ord;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set xy;&lt;/P&gt;&lt;P&gt;by ord;&lt;/P&gt;&lt;P&gt;if first.ord then do;&lt;/P&gt;&lt;P&gt;sumx=x;&lt;/P&gt;&lt;P&gt;sumy=y;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;else do;&lt;/P&gt;&lt;P&gt;sumx+x;&lt;/P&gt;&lt;P&gt;sumy+y;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jag&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 19 Apr 2015 13:45:04 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2015-04-19T13:45:04Z</dc:date>
    <item>
      <title>creating sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-sum-variables/m-p/199312#M49822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm really new to SAS and would appreciate some help..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 19 Apr 2015 04:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-sum-variables/m-p/199312#M49822</guid>
      <dc:creator>CalgaryMom</dc:creator>
      <dc:date>2015-04-19T04:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: creating sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-sum-variables/m-p/199313#M49823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hope this is what you are expecting&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data XY;&lt;/P&gt;&lt;P&gt;input x y;&lt;/P&gt;&lt;P&gt;ord=1;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;18 23&lt;/P&gt;&lt;P&gt;13 20&lt;/P&gt;&lt;P&gt;18 18&lt;/P&gt;&lt;P&gt;15 16&lt;/P&gt;&lt;P&gt;10 14&lt;/P&gt;&lt;P&gt;12 11&lt;/P&gt;&lt;P&gt;8 10&lt;/P&gt;&lt;P&gt;4 7&lt;/P&gt;&lt;P&gt;7 6&lt;/P&gt;&lt;P&gt;3 4&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=xy;&lt;/P&gt;&lt;P&gt;by ord;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set xy;&lt;/P&gt;&lt;P&gt;by ord;&lt;/P&gt;&lt;P&gt;if first.ord then do;&lt;/P&gt;&lt;P&gt;sumx=x;&lt;/P&gt;&lt;P&gt;sumy=y;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;else do;&lt;/P&gt;&lt;P&gt;sumx+x;&lt;/P&gt;&lt;P&gt;sumy+y;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jag&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 19 Apr 2015 13:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-sum-variables/m-p/199313#M49823</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2015-04-19T13:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: creating sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-sum-variables/m-p/199314#M49824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Given your example, what do you want the result to look like?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 19 Apr 2015 14:37:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-sum-variables/m-p/199314#M49824</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2015-04-19T14:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: creating sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-sum-variables/m-p/199315#M49825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Like Fareeza said, such stats are easily calculated using one of the SAS procs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your problem clearly looks like a homework assignment and, if the solution code is your own, your calculation formula is wrong. You would definitely have to capture and use N somewhere in your formula.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can easily include some minor proc sql code to capture and store the desired numbers in macro variables. And you can print them in your log so that you follow your prof's preferred approach. e.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select count(*),sum(x),sum(y),sum(x**2),sum(y**2)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :n,:xsum,:ysum,:x2sum,:y2sum&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from Question1&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;n;&lt;/P&gt;&lt;P&gt;%put &amp;amp;xsum;&lt;/P&gt;&lt;P&gt;%put &amp;amp;ysum;&lt;/P&gt;&lt;P&gt;%put &amp;amp;x2sum;&lt;/P&gt;&lt;P&gt;%put &amp;amp;y2sum;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Conversely, Using the proc print approach, you could do something like the following to get the desired N:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=Question1 n='# of cases:' noobs;&lt;/P&gt;&lt;P&gt;sum x y x2 y2;/*get sums of variables from this table to use in your analysis-I like this way best since I can see the actual calculations*/&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 19 Apr 2015 22:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-sum-variables/m-p/199315#M49825</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2015-04-19T22:59:51Z</dc:date>
    </item>
  </channel>
</rss>

