<?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: Adding data in columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607089#M176375</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Addition to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=base_sample nway;
    class dom;
    var on qc ab sask;
    output out=sum_have sum=;
run;

proc transpose data=sum_have prefix=col_ out=trans_sum_have;
id dom;
var on qc ab sask;
run;

data want;
set trans_sum_have;
Total=sum(of col_:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 25 Nov 2019 19:14:11 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2019-11-25T19:14:11Z</dc:date>
    <item>
      <title>Adding data in columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607085#M176372</link>
      <description>&lt;P&gt;Hi guys.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset like :&lt;/P&gt;&lt;P&gt;data Base_sample;&lt;BR /&gt;input dom ON QC AB Sask ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 2 55 4&lt;BR /&gt;1 5 5 40 6&lt;BR /&gt;2 12 10 15 40&lt;BR /&gt;2 4 20 25 30&lt;BR /&gt;2 5 22 80 70&lt;BR /&gt;3 87 66 44 30&lt;BR /&gt;3 44 42 20 55&lt;BR /&gt;3 55 52 87 90&lt;BR /&gt;3 5 2 6 7&lt;BR /&gt;4 65 45 95 32&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking to get the sum of the ON,QC, AB, Sask in rows (Addition done based on the first column - DOM(Day of month))&lt;/P&gt;&lt;P&gt;My ideal result is :&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Total&lt;/P&gt;&lt;P&gt;ON&amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp;21 191&amp;nbsp; 65&amp;nbsp; &amp;nbsp; &amp;nbsp;283&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;QC&amp;nbsp; &amp;nbsp;7&amp;nbsp; &amp;nbsp;52&amp;nbsp; 162 45&amp;nbsp; &amp;nbsp; &amp;nbsp;266&lt;/P&gt;&lt;P&gt;AB&amp;nbsp; &amp;nbsp;95&amp;nbsp; 120 157 95&amp;nbsp; &amp;nbsp;467&lt;/P&gt;&lt;P&gt;Sask 10&amp;nbsp; 140 182 32&amp;nbsp; 364&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2019 18:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607085#M176372</guid>
      <dc:creator>new_sas_user_4</dc:creator>
      <dc:date>2019-11-25T18:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Adding data in columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607087#M176374</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=base_sample nway;
    class dom;
    var on qc ab sask;
    output out=want sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Nov 2019 19:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607087#M176374</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-25T19:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Adding data in columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607089#M176375</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Addition to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=base_sample nway;
    class dom;
    var on qc ab sask;
    output out=sum_have sum=;
run;

proc transpose data=sum_have prefix=col_ out=trans_sum_have;
id dom;
var on qc ab sask;
run;

data want;
set trans_sum_have;
Total=sum(of col_:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Nov 2019 19:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607089#M176375</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2019-11-25T19:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: Adding data in columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607095#M176378</link>
      <description>&lt;P&gt;Minor fix to my code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=base_sample; /* NWAY option removed */
    class dom;
    var on qc ab sask;
    output out=want sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2019 19:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607095#M176378</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-25T19:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Adding data in columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607104#M176382</link>
      <description>&lt;P&gt;I think this is a case where PROC TABULATE is the best solution.&amp;nbsp; It allows you to both get the SUM statistics you want and organize the data the way you want it, without the transpose or any other subsequent steps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Base_sample;
input dom ON QC AB Sask ;
datalines;
1 1 2 55 4
1 5 5 40 6
2 12 10 15 40
2 4 20 25 30
2 5 22 80 70
3 87 66 44 30
3 44 42 20 55
3 55 52 87 90
3 5 2 6 7
4 65 45 95 32
;

*ods results off;
*ods listing close;
proc tabulate data=base_sample  /*out=mytable (drop=_:)*/;
  class dom ;
  var on qc ab sask;
  tables (on qc ab sask)     /* Row specification */
          ,sum=' '*dom       /* Column specification */
  ;
run;
*ods results open;
*ods listing ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want an immediate printout of the results then don't bother changing my commented statements.&amp;nbsp; But if you don't (maybe there are 1,000 values of DOM, and you don't want to print 1,000 rows), then select the output destinations currently in use in your sas sessions, and de-comment the corresponding statements before and after the proc tabulate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2019 19:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607104#M176382</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-11-25T19:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: Adding data in columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607116#M176390</link>
      <description>&lt;P&gt;Thanks a lot &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;I do have another column which I need the data to be grouped by.&lt;/P&gt;&lt;P&gt;I didnt include it earlier as I thought I would be able to do it myself if I have the basic query to start off but using transpose I suppose I cant as &lt;STRONG&gt;ID would be unique values.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Sorry to bother again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the sample&amp;nbsp;data Base_sample;&lt;BR /&gt;length item $1;&lt;BR /&gt;input item $ dom On QC AB Sask ;&lt;BR /&gt;datalines;&lt;BR /&gt;A 1 1 2 55 4&lt;BR /&gt;B 1 5 5 40 6&lt;BR /&gt;A 2 12 10 15 40&lt;BR /&gt;A 2 4 20 25 30&lt;BR /&gt;B 2 5 22 80 70&lt;BR /&gt;A 3 87 66 44 30&lt;BR /&gt;A 3 44 42 20 55&lt;BR /&gt;B 3 55 52 87 90&lt;BR /&gt;C 3 5 2 6 7&lt;BR /&gt;C 4 65 45 95 32&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected :&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 392px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34230i86C702BD56859012/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2019 20:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607116#M176390</guid>
      <dc:creator>new_sas_user_4</dc:creator>
      <dc:date>2019-11-25T20:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: Adding data in columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607123#M176394</link>
      <description>&lt;P&gt;Either of these will work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;PROC SUMMARY with both ITEM and DOM in the class statement&lt;/LI&gt;
&lt;LI&gt;PROC REPORT&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Mon, 25 Nov 2019 20:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607123#M176394</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-25T20:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Adding data in columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607127#M176396</link>
      <description>&lt;P&gt;But then how would I transpose &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; sorry I am a noob&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2019 21:44:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-data-in-columns/m-p/607127#M176396</guid>
      <dc:creator>new_sas_user_4</dc:creator>
      <dc:date>2019-11-25T21:44:33Z</dc:date>
    </item>
  </channel>
</rss>

