<?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: Data Transformation SAS Help: from Rows to Columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/504001#M134810</link>
    <description>&lt;PRE&gt;
This produce the Astounding's code .



data want;

merge have (where=(metric='Sales') rename=(actual=Sales_Actual forecast=Sales_Forecast total=Sales_Total))

have (where=(metric='Profit') rename=(actual=Profit_Actual forecast=Profit_Forecast total=Profit_Total));

by product;

drop metric;

run;


&lt;/PRE&gt;</description>
    <pubDate>Sat, 13 Oct 2018 10:21:08 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-10-13T10:21:08Z</dc:date>
    <item>
      <title>Data Transformation SAS Help: from Rows to Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503555#M134581</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to transform how my data is laid out. The data that I am starting with is formatted as such:&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Product&lt;/TD&gt;&lt;TD&gt;Metric&lt;/TD&gt;&lt;TD&gt;Actual&lt;/TD&gt;&lt;TD&gt;Forecast&lt;/TD&gt;&lt;TD&gt;Total&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Sales&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Profit&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;Sales&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;Profit&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to transform my data to look like this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Product&lt;/TD&gt;&lt;TD&gt;Sales Actual&lt;/TD&gt;&lt;TD&gt;Sales Forecast&lt;/TD&gt;&lt;TD&gt;Sales Total&lt;/TD&gt;&lt;TD&gt;Profit Actual&lt;/TD&gt;&lt;TD&gt;Profit Forecast&lt;/TD&gt;&lt;TD&gt;Profit Total&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am newer to SAS, but have had success with transposing data in the past though i have not been able to get it to work with this dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for the help,&lt;/P&gt;&lt;P&gt;Emily&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 20:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503555#M134581</guid>
      <dc:creator>ecc14</dc:creator>
      <dc:date>2018-10-11T20:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation SAS Help: from Rows to Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503558#M134583</link>
      <description>&lt;P&gt;Here's one way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;merge have (where=(metric='Sales') rename=(actual=Sales_Actual forecast=Sales_Forecast total=Sales_Total))&lt;/P&gt;
&lt;P&gt;have (where=(metric='Profit') rename=(actual=Profit_Actual forecast=Profit_Forecast total=Profit_Total));&lt;/P&gt;
&lt;P&gt;by product;&lt;/P&gt;
&lt;P&gt;drop metric;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It assumes your data set is already sorted by PRODUCT.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 20:40:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503558#M134583</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-11T20:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation SAS Help: from Rows to Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503568#M134586</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Product $	Metric $	Actual	Forecast	Total;
cards;
A	Sales	10	10	20
A	Profit	5	5	10
B	Sales	20	20	40
B	Profit	15	15	30
;

proc transpose data=have out=_have;
by product metric notsorted;
var Actual	Forecast	Total;
run;

proc transpose data=_have out=want;
by product;
var col1;
id metric _name_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Oct 2018 20:54:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503568#M134586</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-11T20:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation SAS Help: from Rows to Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503571#M134588</link>
      <description>&lt;P&gt;Thank you so much Astounding! This&amp;nbsp;worked for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 21:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503571#M134588</guid>
      <dc:creator>ecc14</dc:creator>
      <dc:date>2018-10-11T21:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation SAS Help: from Rows to Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503572#M134589</link>
      <description>&lt;P&gt;I don't think astounding solution is a proper automated solution. In my opinion that's hard coding and will not scale if the number of metric changes.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 21:12:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503572#M134589</guid>
      <dc:creator>Andygray</dc:creator>
      <dc:date>2018-10-11T21:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation SAS Help: from Rows to Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503700#M134646</link>
      <description>&lt;P&gt;OK. Merge Skill come to rescue. proposed by me,Matt,Arthur.T:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Product $	Metric $	Actual	Forecast	Total;
cards;
A	Sales	10	10	20
A	Profit	5	5	10
B	Sales	20	20	40
B	Profit	15	15	30
;

proc sort data=have(keep=Metric) out=key nodupkey;
by Metric;
run;
data _null_;
 set key end=last;
 if _n_=1 then call execute('data want;merge ');
 call execute(catt('have(where=(Metric="',Metric,'") 
 rename=(Actual=',Metric,'_Actual Forecast=',Metric,'_Forecast Total=',Metric,'_Total))'));
 if last then call execute(';by Product;drop Metric;run;');
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Oct 2018 12:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503700#M134646</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-12T12:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation SAS Help: from Rows to Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503702#M134647</link>
      <description>&lt;P&gt;OK. Merge Skill come to rescue. proposed by me,Matt,Arthur.T:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Product $	Metric $	Actual	Forecast	Total;
cards;
A	Sales	10	10	20
A	Profit	5	5	10
B	Sales	20	20	40
B	Profit	15	15	30
;

proc sort data=have(keep=Metric) out=key nodupkey;
by Metric;
run;
data _null_;
 set key end=last;
 if _n_=1 then call execute('data want;merge ');
 call execute(catt('have(where=(Metric="',Metric,'") 
 rename=(Actual=',Metric,'_Actual Forecast=',Metric,'_Forecast Total=',Metric,'_Total))'));
 if last then call execute(';by Product;drop Metric;run;');
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Oct 2018 12:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503702#M134647</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-12T12:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation SAS Help: from Rows to Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503861#M134730</link>
      <description>&lt;P&gt;Do you mind walking me through what you are doing here? I'm not sure I am following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;call &lt;SPAN class="token keyword"&gt;execute&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;catt&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'have(where=(Metric="'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;Metric&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'") 
 rename=(Actual='&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;Metric&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'_Actual Forecast='&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;Metric&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'_Forecast Total='&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;Metric&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'_Total))'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; last &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; call &lt;SPAN class="token keyword"&gt;execute&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;';by Product;drop Metric;run;'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 19:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/503861#M134730</guid>
      <dc:creator>ecc14</dc:creator>
      <dc:date>2018-10-12T19:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation SAS Help: from Rows to Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/504001#M134810</link>
      <description>&lt;PRE&gt;
This produce the Astounding's code .



data want;

merge have (where=(metric='Sales') rename=(actual=Sales_Actual forecast=Sales_Forecast total=Sales_Total))

have (where=(metric='Profit') rename=(actual=Profit_Actual forecast=Profit_Forecast total=Profit_Total));

by product;

drop metric;

run;


&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Oct 2018 10:21:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-SAS-Help-from-Rows-to-Columns/m-p/504001#M134810</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-13T10:21:08Z</dc:date>
    </item>
  </channel>
</rss>

