<?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: How to fix a Total column as the last column after each merge ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-fix-a-Total-column-as-the-last-column-after-each-merge/m-p/744984#M233470</link>
    <description>&lt;P&gt;Variable names?&lt;/P&gt;
&lt;P&gt;Code used to "merge" data sets?&lt;/P&gt;
&lt;P&gt;Actual example data?&lt;/P&gt;
&lt;P&gt;Possible even how you calculate the total prior to merging is of interest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;90% percent of the time I see something like this a report procedure with the proper data structure handles stuff correctly. Order of columns in a data set is generally not of much importance as the computers using the data do not care, only people. And that means Report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And please look at the posted information. It is quite likely that the message window on this forum already reformatted text moving the "total" column to different columns. So what we see is not what we can do much with.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Jun 2021 16:12:36 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-06-01T16:12:36Z</dc:date>
    <item>
      <title>How to fix a Total column as the last column after each merge ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-fix-a-Total-column-as-the-last-column-after-each-merge/m-p/744977#M233467</link>
      <description>&lt;P&gt;I have a dataset with a Total column for each month data. Every time i run the report for subsequent month the new report gets merged with the previous month's report. But the Total column is coming before the 2nd months data. I want this total column to always be the last column in the report and this column should contain the sum total value from the each row. How can I do this ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output i am getting is : after 1st run&amp;nbsp; metric&amp;nbsp; Jan Total&amp;nbsp;&lt;/P&gt;&lt;P&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;after 2nd run&amp;nbsp; metric&amp;nbsp; Jan Total Feb&lt;/P&gt;&lt;P&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;after 1st run&amp;nbsp; metric&amp;nbsp; Jan Total Feb Mar&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output i want is : after 1st run&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; metric Jan Total&lt;/P&gt;&lt;P&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;after 2nd run&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;metric Jan&amp;nbsp; Feb Total&lt;/P&gt;&lt;P&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;after 3rd run&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;metric Jan&amp;nbsp; Feb&amp;nbsp; Mar Total&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting the correct summation data in the total column with each run only the arrangement I am not able to fix.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/38890"&gt;@cynthia&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 15:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-fix-a-Total-column-as-the-last-column-after-each-merge/m-p/744977#M233467</guid>
      <dc:creator>sasuser58</dc:creator>
      <dc:date>2021-06-01T15:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to fix a Total column as the last column after each merge ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-fix-a-Total-column-as-the-last-column-after-each-merge/m-p/744984#M233470</link>
      <description>&lt;P&gt;Variable names?&lt;/P&gt;
&lt;P&gt;Code used to "merge" data sets?&lt;/P&gt;
&lt;P&gt;Actual example data?&lt;/P&gt;
&lt;P&gt;Possible even how you calculate the total prior to merging is of interest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;90% percent of the time I see something like this a report procedure with the proper data structure handles stuff correctly. Order of columns in a data set is generally not of much importance as the computers using the data do not care, only people. And that means Report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And please look at the posted information. It is quite likely that the message window on this forum already reformatted text moving the "total" column to different columns. So what we see is not what we can do much with.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 16:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-fix-a-Total-column-as-the-last-column-after-each-merge/m-p/744984#M233470</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-01T16:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to fix a Total column as the last column after each merge ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-fix-a-Total-column-as-the-last-column-after-each-merge/m-p/744986#M233471</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/384053"&gt;@sasuser58&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a dataset with a Total column for each month data. Every time i run the report for subsequent month the new report gets merged with the previous month's report. But the Total column is coming before the 2nd months data. I want this total column to always be the last column in the report and this column should contain the sum total value from the each row. How can I do this ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output i am getting is : after 1st run&amp;nbsp; metric&amp;nbsp; Jan Total&amp;nbsp;&lt;/P&gt;
&lt;P&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;after 2nd run&amp;nbsp; metric&amp;nbsp; Jan Total Feb&lt;/P&gt;
&lt;P&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;after 1st run&amp;nbsp; metric&amp;nbsp; Jan Total Feb Mar&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output i want is : after 1st run&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; metric Jan Total&lt;/P&gt;
&lt;P&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;after 2nd run&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;metric Jan&amp;nbsp; Feb Total&lt;/P&gt;
&lt;P&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;after 3rd run&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;metric Jan&amp;nbsp; Feb&amp;nbsp; Mar Total&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am getting the correct summation data in the total column with each run only the arrangement I am not able to fix.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In most cases (nearly all cases), it isn't worth fighting with SAS to get the proper order of columns in a SAS data set. Why? Because any output method (PROC PRINT, PROC REPORT, PROC TABULATE), you can specify the desired order of columns there. And it's much much simpler to specify the order of columns in your output procedure than in your data set.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 16:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-fix-a-Total-column-as-the-last-column-after-each-merge/m-p/744986#M233471</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-01T16:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to fix a Total column as the last column after each merge ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-fix-a-Total-column-as-the-last-column-after-each-merge/m-p/744987#M233472</link>
      <description>&lt;P&gt;Rather than use month names use MONTH1-MONTH12 and then total.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use labels to display the month and total.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can add a step as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ordered_data;
retain Month1-Month12 Total;
set myData;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A better solution is to not store your data in that format and to use a long format instead. You can use PROC REPORT/TABULATE to display it as desired but the long format will give you more control. Or store it that way in a long format with the months as numbers and Total gets 99. Then flip it using PROC TRANSPOSE as your last step that will then have everything in order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Store it this way&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Month Metric Value
1 Mean 24
2 Mean 24
...
12 Mean 55
99 Mean 900

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then transpose it and it should keep the order desired. But otherwise you'll have to manually specify the months in a macro variable or something because those are in an order that is not alphabetical or ordered in any fashion.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 16:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-fix-a-Total-column-as-the-last-column-after-each-merge/m-p/744987#M233472</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-01T16:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to fix a Total column as the last column after each merge ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-fix-a-Total-column-as-the-last-column-after-each-merge/m-p/744990#M233475</link>
      <description>&lt;P&gt;Depends on how you are combining them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One easy way is to use dataset options to force SAS to define the variables in the order you want.&amp;nbsp; SAS will set the order based on when it first "sees" the variable.&amp;nbsp; For example you could have a SET statement than can never actually be executed but the compiler will still check the variables that it provides.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if 1=0 then set old (drop=total) ;
  set old new ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 16:43:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-fix-a-Total-column-as-the-last-column-after-each-merge/m-p/744990#M233475</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-01T16:43:54Z</dc:date>
    </item>
  </channel>
</rss>

