<?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: Converting Date Values from Date Variable to new columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-Date-Values-from-Date-Variable-to-new-columns/m-p/867184#M342468</link>
    <description>&lt;P&gt;First, create the ACROSS variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data prepared;
set have;
cat = cats(substr(accounttype,1,1),month(transdate));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use it in the report:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=prepared;
column idcc amount,cat;
define idcc / group;
define amount / "" analysis sum;
define cat / "" across;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 30 Mar 2023 07:15:51 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-03-30T07:15:51Z</dc:date>
    <item>
      <title>Converting Date Values from Date Variable to new columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Date-Values-from-Date-Variable-to-new-columns/m-p/867183#M342467</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that looks something like this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;IDCC&lt;/TD&gt;&lt;TD&gt;TransDate&lt;/TD&gt;&lt;TD&gt;Amount&lt;/TD&gt;&lt;TD&gt;AccountType&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;55555&lt;/TD&gt;&lt;TD&gt;11-Jun-03&lt;/TD&gt;&lt;TD&gt;114.56&lt;/TD&gt;&lt;TD&gt;Savings&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;55555&lt;/TD&gt;&lt;TD&gt;12-Jun-03&lt;/TD&gt;&lt;TD&gt;119.56&lt;/TD&gt;&lt;TD&gt;Savings&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;55555&lt;/TD&gt;&lt;TD&gt;21-Jun-03&lt;/TD&gt;&lt;TD&gt;-56.78&lt;/TD&gt;&lt;TD&gt;Checking&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;55555&lt;/TD&gt;&lt;TD&gt;7-Jul-03&lt;/TD&gt;&lt;TD&gt;359.31&lt;/TD&gt;&lt;TD&gt;Savings&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;55555&lt;/TD&gt;&lt;TD&gt;19-Jul-03&lt;/TD&gt;&lt;TD&gt;89.56&lt;/TD&gt;&lt;TD&gt;Checking&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;55555&lt;/TD&gt;&lt;TD&gt;3-Aug-03&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;TD&gt;Savings&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;77777&lt;/TD&gt;&lt;TD&gt;3-Dec-03&lt;/TD&gt;&lt;TD&gt;645.21&lt;/TD&gt;&lt;TD&gt;Savings&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;55555&lt;/TD&gt;&lt;TD&gt;17-Aug-03&lt;/TD&gt;&lt;TD&gt;-1200&lt;/TD&gt;&lt;TD&gt;Checking&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the final output to look something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;IDCC&lt;/TD&gt;&lt;TD&gt;C6&lt;/TD&gt;&lt;TD&gt;C7&lt;/TD&gt;&lt;TD&gt;C8&lt;/TD&gt;&lt;TD&gt;S6&lt;/TD&gt;&lt;TD&gt;S7&lt;/TD&gt;&lt;TD&gt;S8&lt;/TD&gt;&lt;TD&gt;S12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;55555&lt;/TD&gt;&lt;TD&gt;-56.78&lt;/TD&gt;&lt;TD&gt;89.56&lt;/TD&gt;&lt;TD&gt;-1200&lt;/TD&gt;&lt;TD&gt;234.12&lt;/TD&gt;&lt;TD&gt;359.31&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;77777&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;645.21&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where&amp;nbsp;C6 - Checking for Jun, C7 - Checking for Jul, C8 - Checking for Aug&amp;nbsp;&lt;/P&gt;&lt;P&gt;and&amp;nbsp;S6 - Savings for Jun, S7- Savings for Jul, S8- Savings for Aug, S12- Savings for Dec.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is, how do I rename the new columns based on the desired output? I understand I can just sort the data by IDC,&amp;nbsp;account type and date, do a proc transpose and rename the variables accordingly. But I intend on using macro to rename the variables to the desired output. Any input is very much appreciated. Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 06:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Date-Values-from-Date-Variable-to-new-columns/m-p/867183#M342467</guid>
      <dc:creator>nanmz</dc:creator>
      <dc:date>2023-03-30T06:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Date Values from Date Variable to new columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Date-Values-from-Date-Variable-to-new-columns/m-p/867184#M342468</link>
      <description>&lt;P&gt;First, create the ACROSS variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data prepared;
set have;
cat = cats(substr(accounttype,1,1),month(transdate));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use it in the report:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=prepared;
column idcc amount,cat;
define idcc / group;
define amount / "" analysis sum;
define cat / "" across;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Mar 2023 07:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Date-Values-from-Date-Variable-to-new-columns/m-p/867184#M342468</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-30T07:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Date Values from Date Variable to new columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Date-Values-from-Date-Variable-to-new-columns/m-p/867266#M342513</link>
      <description>&lt;P&gt;And if you really think that you need a data set this &lt;STRONG&gt;may&lt;/STRONG&gt; work, using the data set &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; suggests:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc summary data=prepdate nway;
   class idcc cat;
   var amount;
   output out=summed(drop=_:) sum=;
run;

proc transpose data=summed out=want;
   by idcc;
   id cat;
   var amount;
run;&lt;/PRE&gt;
&lt;P&gt;The summary step is to get a single total for amount for the Cat groups within the ID. Transpose places it into the wide format you requested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Caution: You do not show any data for more than a few months and does show more than one calendar year. IF your data actually comes from more than one year then your shown desired format could well include values from more than one year in a month. So you may want to rethink this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do note that you can use date values as groups just using the proper format and may be a more useful approach for reports:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  input IDCC	TransDate :anydtdte.	Amount	AccountType $;
  format transdate ddmmyy10.;
datalines;
55555	11-Jun-03	114.56	Savings
55555	12-Jun-03	119.56	Savings
55555	21-Jun-03	-56.78	Checking
55555	7-Jul-03	359.31	Savings
55555	19-Jul-03	89.56	Checking
55555	3-Aug-03	1000	Savings
77777	3-Dec-03	645.21	Savings
55555	17-Aug-03	-1200	Checking
;

proc report data=have;
   columns idcc Accounttype ,Transdate,amount;
   define idcc /group;
   define accounttype/across '' ;
   define transdate/across format=monyy7. '';
run;&lt;/PRE&gt;
&lt;P&gt;OR you could summarize using the AccountType and Transdate with the MONYY7, or other year and month format, to get the totals then add the cat variable using the month and year info before transposing&lt;/P&gt;
&lt;P&gt;Lots of other ways to do things depending on what comes next.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please not the data step above. That is the way to provide example data so we do not have to guess properties of variables and can test code against data similar to yours. Paste the code into a text box opened on the forum with the &amp;lt;/&amp;gt; icon above the message window as the forum software will reformat text pasted into the main windows and may result in code that will not run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 14:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Date-Values-from-Date-Variable-to-new-columns/m-p/867266#M342513</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-30T14:59:55Z</dc:date>
    </item>
  </channel>
</rss>

