<?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 arrange dates using proc transpose and adding the total? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676615#M79331</link>
    <description>&lt;P&gt;Do you want the result to be a SAS data set, or do you want it to be a report?&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Thu, 13 Aug 2020 23:21:34 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-08-13T23:21:34Z</dc:date>
    <item>
      <title>How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676613#M79330</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a data from the last 12 months and need help on how to transpose the date in order, group by IDs and getting the total count. Please advise&lt;/P&gt;
&lt;P&gt;Version - SAS M6&lt;/P&gt;
&lt;P&gt;See sample dataset below:&lt;/P&gt;
&lt;PRE&gt;data dataset;
input id $1-3 yrmth 5-10 count 12;
datalines;
001 201911 2
001 201912 1
001 201903 1
001 202004 5
001 202006 1
002 201908 1
002 201909 2
002 201909 1
002 201910 1
003 202001 4
003 202002 3
003 202005 2
003 202007 1;
run;&lt;/PRE&gt;
&lt;P&gt;EXPECTED RESULT:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;ID&lt;/FONT&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 201908&amp;nbsp;201909&amp;nbsp;201910&amp;nbsp;201911&amp;nbsp;201912&amp;nbsp; 202001&amp;nbsp;202002&amp;nbsp;202003&amp;nbsp;202004&amp;nbsp;202005&amp;nbsp;202006&amp;nbsp;202007&amp;nbsp; &lt;FONT color="#0000FF"&gt;TOTAL&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;001&lt;/FONT&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#0000FF"&gt;10&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;002&lt;/FONT&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#0000FF"&gt;5&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;003&lt;/FONT&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;FONT color="#0000FF"&gt;10&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 23:18:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676613#M79330</guid>
      <dc:creator>mrafael03</dc:creator>
      <dc:date>2020-08-13T23:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676615#M79331</link>
      <description>&lt;P&gt;Do you want the result to be a SAS data set, or do you want it to be a report?&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 13 Aug 2020 23:21:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676615#M79331</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-13T23:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676617#M79332</link>
      <description>It should be a dataset since i need to do a linkage on another table to create a summary report&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Aug 2020 23:24:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676617#M79332</guid>
      <dc:creator>mrafael03</dc:creator>
      <dc:date>2020-08-13T23:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676619#M79333</link>
      <description>&lt;P&gt;I'm skeptical that creating a wide data set from a long data set is a good idea ... usually, it is not a good idea and makes your coding harder. So please explain further this "linkage on another table".&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 13 Aug 2020 23:28:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676619#M79333</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-13T23:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676621#M79334</link>
      <description>&lt;P&gt;From my first data set&amp;nbsp; I have the data from the last 12 months&lt;/P&gt;
&lt;P&gt;Variable includes:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;ID&lt;/LI&gt;
&lt;LI&gt;YEARMONTH&lt;/LI&gt;
&lt;LI&gt;COUNT&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Then, I'll do a linkage between member info table that includes:&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;ID&lt;/LI&gt;
&lt;LI&gt;Member Demographics&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;FINAL Report will include&lt;/P&gt;
&lt;P&gt;ID, Member Demographics, YearMonth (12 months), Total Count&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAMPLE OUTPUT&lt;/P&gt;
&lt;P&gt;ID Name Phone&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;201908&amp;nbsp;&amp;nbsp;201909&amp;nbsp;&amp;nbsp;201910&amp;nbsp;&amp;nbsp;201911&amp;nbsp;&amp;nbsp;201912&amp;nbsp;&amp;nbsp;202001&amp;nbsp;&amp;nbsp;2019......&amp;nbsp; TOTAL&lt;/P&gt;
&lt;P&gt;001 Ana&amp;nbsp; 888#####&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 23:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676621#M79334</guid>
      <dc:creator>mrafael03</dc:creator>
      <dc:date>2020-08-13T23:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676623#M79335</link>
      <description>&lt;P&gt;So, again the idea of transposing to a wide data set seems unnecessary to me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset;
input id $1-3 yrmth 5-10 count 12;
datalines;
001 201911 2
001 201912 1
001 201903 1
001 202004 5
001 202006 1
002 201908 1
002 201909 2
002 201909 1
002 201910 1
003 202001 4
003 202002 3
003 202005 2
003 202007 1
;
proc sql;
	create table two as select a.*,b.name,b.phone
		from dataset a left join demographics b
		on a.id=b.id;
quit;
proc report data=two;
    columns id name phone yrmth,count count=total;
    define id / group;
    define name / group;
    define phone / group;
    define yrmth / across;
    define count / sum;
    define total / 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>Fri, 14 Aug 2020 00:08:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676623#M79335</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-14T00:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676624#M79336</link>
      <description>I think I have a wrong approach. Tried the code and I think that's not what I'm looking for.&lt;BR /&gt;&lt;BR /&gt;So basically, I have the 1st dataset and my goal is to add it on the existing table that consist of member table. I'm not sure on how I will add the yearmonth in order plus the total without hard coding it.&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;proc sql; &lt;BR /&gt;create table test as select&lt;BR /&gt;a.id, a.fullname, b.aug2019, b.sept2019, b.oct2019, b.nov2019, b.dec2019,b.jan2020, &lt;BR /&gt;b.feb2020, b.mar2020, b.apr2020, b.may2020, b.jun2020, b.july2020,&lt;BR /&gt;(b.aug2019 + b.sept2019 + b.oct2019 + b.nov2019 + b.dec2019 + b.jan2020 + &lt;BR /&gt;b.feb2020 + b.mar2020 + b.apr2020 + b.may2020 + b.jun2020, b.july2020) as total label='total counts'&lt;BR /&gt;from member_tbl a&lt;BR /&gt;left join dataset1 b on a.id=b.id&lt;BR /&gt;order by id&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Aug 2020 00:49:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676624#M79336</guid>
      <dc:creator>mrafael03</dc:creator>
      <dc:date>2020-08-14T00:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676626#M79337</link>
      <description>&lt;P&gt;Now you see the problem with wide datasets and how difficult they are to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code I provided ought to work, or something similar ought to work, kbut you don't explain why you don't like it.&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Fri, 14 Aug 2020 01:04:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676626#M79337</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-14T01:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676627#M79338</link>
      <description>so i’m looking for a result that will automatically populate the year month accordingly. It might be a combination of transpose + macro?</description>
      <pubDate>Fri, 14 Aug 2020 01:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676627#M79338</guid>
      <dc:creator>mrafael03</dc:creator>
      <dc:date>2020-08-14T01:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676642#M79341</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;about the discussion wide versus long.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you want to go this way, here is a sample that gets you close. Please note, SAS does not allow for variable names to start with a digit by default. You have to set SAS System Option VALIDVARNAME=ANY. This then also means you have to use a name literal for those new names like so '201909'n.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset;
  input id $1-3 yrmth 5-10 count 12;
  datalines;
001 201911 2
001 201912 1
001 201903 1
001 202004 5
001 202006 1
002 201908 1
002 201909 2
002 201909 1
002 201910 1
003 202001 4
003 202002 3
003 202005 2
003 202007 1
;

/*
 * create orderd lit of column names
 */
proc sql noprint;
  select distinct
    cats("'", yrmth, "'n")
  into
    :yrmth_list separated by " "
  from
    dataset
  order by
    1
  ;
quit;

%put NOTE: &amp;amp;=yrmth_list;

/*
 * create an empty base table
 * using the list from above
 */
data basetable;
  length
    id $ 3
    &amp;amp;yrmth_list 8
  ;
  stop;
run;

/*
 * aggregate data, since some yrmth appear more tan once
 */
proc sql;
  create table dataset_aggr as
    select
      id
      , yrmth
      , sum(count) as count
    from
      dataset
    group by
      id
      , yrmth
  ;
quit;

/*
 * transpose the data
 */
proc transpose
  data=dataset_aggr
  out=ds_trsp(drop=_name_)
;
  by id;
  id yrmth;
  var count;
run;

/*
 * append t base table
 */
proc append
  base=basetable
  data=ds_trsp
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Aug 2020 06:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676642#M79341</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2020-08-14T06:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676682#M79342</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321952"&gt;@mrafael03&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;so i’m looking for a result that will automatically populate the year month accordingly. It might be a combination of transpose + macro?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PROC REPORT will do this easily without macro and without a transpose. You still haven't specified what was wrong with the results from the PROC REPORT I showed, and its possible that a relatively minor change to the above code will do what you want.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 12:05:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676682#M79342</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-14T12:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676684#M79343</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller&lt;/a&gt; thank you for confirming my point of view. Your code takes a lot more effort than PROC REPORT from a long data set.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 11:05:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676684#M79343</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-14T11:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676687#M79345</link>
      <description>&lt;P&gt;Totally agree Proc REPORT would be far less code, but I guess it all depends on what type of output is needed, report, data, ...&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 11:17:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676687#M79345</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2020-08-14T11:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676699#M79347</link>
      <description>&lt;P&gt;There is a function for converting names into name literals.&amp;nbsp; Of course you still need to convert the number into a string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; nliteral(cats(yrmth))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Aug 2020 11:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676699#M79347</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-14T11:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676777#M79350</link>
      <description>&lt;P&gt;&lt;FONT size="2"&gt;Thanks for the sample code &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller&lt;/a&gt;&amp;nbsp;really appreciate it.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;I have these codes on my original script. What I'm trying to achieve is on how I will include the 12 month period "YEARMONTH" on my final report without hard coding it as shown above&lt;/FONT&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;/*aggregate data, since some yrmth appear more tan once*/
proc sql;
create table dataset_aggr as select
id
,yrmth
,sum(count) as count
from dataset
group by id,yrmth;
quit;

/*transpose the data*/
proc transpose data=dataset_aggr out=ds_trsp(drop=_name_);
  by id;
  id yrmth;
  var count;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 15:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676777#M79350</guid>
      <dc:creator>mrafael03</dc:creator>
      <dc:date>2020-08-14T15:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676782#M79351</link>
      <description>&lt;P&gt;Either create the total as a separate row in the TALL dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table dataset_aggr as select
 id
,cats(yrmth) as name length=6
,sum(count) as count
from dataset
group by id,yrmth
union
select
 id
,'TOTAL' as name length=6
,sum(count) as count
from dataset
group by id
;
quit;
...
  id name;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or create the total in the WIDE dataset.&lt;/P&gt;
&lt;P&gt;The second will be easy if ID is character.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set ds_trsp;
  total=sum(of _numeric);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or make your transposed dataset have rational and uniquely prefixed valid SAS names by using the PREFIX= option on PROC TRANSPOSE so you can use a prefixed variable list in the SUM() function call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose prefix=YYMM_ ....
...
  total=sum(of YYMM_:);
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 16:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676782#M79351</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-14T16:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676834#M79352</link>
      <description>&lt;P&gt;Please see attached expected output. Hopefully this is helpful&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 18:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676834#M79352</guid>
      <dc:creator>mrafael03</dc:creator>
      <dc:date>2020-08-14T18:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676839#M79353</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Now you see the problem with wide datasets and how difficult they are to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code I provided ought to work, or something similar ought to work, kbut you don't explain why you don't like it.&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;Hi, again I tried your codes and it's actually worked and closer to what I'm looking for. Please see attached file for sample output that I'm aiming for&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 19:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/676839#M79353</guid>
      <dc:creator>mrafael03</dc:creator>
      <dc:date>2020-08-14T19:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to arrange dates using proc transpose and adding the total?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/677624#M79373</link>
      <description>&lt;P&gt;Your Proc REPORT is very close to what you want, just some minor changes:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;In the COLUMN statement you can either use acrossVar, analysisVar or&amp;nbsp;analysisVar, acrossVar, see below&lt;/LI&gt;
&lt;LI&gt;add an empty column label, this will suppress the printing&lt;/LI&gt;
&lt;LI&gt;adding the statement&amp;nbsp;options missing="0"; before Proc REPORT will print a 0 instead of ., please set it back to . after Proc REPORT&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;You can send the output directly to Excel using ODS EXCEL, as it looks like you want to have it in Excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc report data=two;
    columns id name age count, yrmth count=total;
    define id / group;
    define name / group;
    define age / group;
    define yrmth / across " ";
    define count / sum " ";
    define total / sum "Total";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Aug 2020 20:01:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-arrange-dates-using-proc-transpose-and-adding-the-total/m-p/677624#M79373</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2020-08-18T20:01:44Z</dc:date>
    </item>
  </channel>
</rss>

