<?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: Transpose Table With Columns for Each Month to One Row Per Month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transpose-Table-With-Columns-for-Each-Month-to-One-Row-Per-Month/m-p/910523#M359075</link>
    <description>Thanks this is perfect. I will follow that post from now on</description>
    <pubDate>Thu, 04 Jan 2024 20:09:44 GMT</pubDate>
    <dc:creator>cartergay</dc:creator>
    <dc:date>2024-01-04T20:09:44Z</dc:date>
    <item>
      <title>Transpose Table With Columns for Each Month to One Row Per Month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-Table-With-Columns-for-Each-Month-to-One-Row-Per-Month/m-p/910517#M359072</link>
      <description>&lt;P&gt;I have a table with the following columns:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Member_ID&lt;/LI&gt;&lt;LI&gt;Contract_Jan, ..., Contract_Dec&lt;/LI&gt;&lt;LI&gt;PBP_Jan, ..., PBP_Dec&lt;/LI&gt;&lt;LI&gt;Cost_Sharing_Jan, ..., Cost_Sharing_Dec&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I would like to transpose this table into the following format:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Member_ID&lt;/LI&gt;&lt;LI&gt;Month&lt;/LI&gt;&lt;LI&gt;Contract&lt;/LI&gt;&lt;LI&gt;PBP&lt;/LI&gt;&lt;LI&gt;Cost_Sharing&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I want to avoid using PROC SQL union all since the data I am querying is extremely large&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 19:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-Table-With-Columns-for-Each-Month-to-One-Row-Per-Month/m-p/910517#M359072</guid>
      <dc:creator>cartergay</dc:creator>
      <dc:date>2024-01-04T19:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose Table With Columns for Each Month to One Row Per Month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-Table-With-Columns-for-Each-Month-to-One-Row-Per-Month/m-p/910520#M359073</link>
      <description>&lt;P&gt;Good idea to avoid PROC SQL here. I don't even know if SQL can do this transpose, but I'm sure I don't want to try to figure out how to program it in SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From now on, please provide a portion of your data following these &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and isntructions&lt;/A&gt;. Here is fake data converted to the requested format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input member_id contract_jan contract_feb contract_mar contract_apr pbp_jan pbp_feb pbp_mar pbp_apr cost_sharing_jan cost_sharing_feb
        cost_sharing_mar cost_sharing_apr;
    cards;
123 1 2 3 4 5 6 7 8 9 10 11 12
143 13 14 15 16 17 18 19 20 21 22 23 24
431 14 24 34 44 54 64 74 84 94 104 114 12
999 135 145 155 165 175 185 195 205 215 225 235 24
;

data want;
    set have;
    array c contract:;
    array p pbp:;
    array cs cost_sharing:;
    do i=1 to dim(c);
        _contract=c(i);
        _pbp=p(i);
        _cost_sharing=cs(i);
        monthname=scan(vname(c(i)),2,'_');
        date=input(cats('01',monthname,'2019'),date9.);
        output;
    end;
    drop i contract: pbp: cost_sharing: monthname;
    format date monyy7.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition, it would be wise not to work with months as character strings; a better way to handle this is to turn these month character strings into actual valid SAS date values. I have done this in the code above, stealing a method from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565497#M158788" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 20:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-Table-With-Columns-for-Each-Month-to-One-Row-Per-Month/m-p/910520#M359073</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-04T20:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose Table With Columns for Each Month to One Row Per Month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-Table-With-Columns-for-Each-Month-to-One-Row-Per-Month/m-p/910523#M359075</link>
      <description>Thanks this is perfect. I will follow that post from now on</description>
      <pubDate>Thu, 04 Jan 2024 20:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-Table-With-Columns-for-Each-Month-to-One-Row-Per-Month/m-p/910523#M359075</guid>
      <dc:creator>cartergay</dc:creator>
      <dc:date>2024-01-04T20:09:44Z</dc:date>
    </item>
  </channel>
</rss>

