<?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: reshape observations als variables ore viceversa in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/reshape-observations-als-variables-ore-viceversa/m-p/298669#M62840</link>
    <description>&lt;P&gt;On the one hand, I agree with those who contend that COST has the "right" structure and REVENUE has the "wrong" structure.&amp;nbsp; On the other hand, it's not for me to pre-judge the requirements that you will encounter in your future programming.&amp;nbsp; With that said, here is how you might transpose the COST data into the REVENUE structure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc transpose data=cost prefix=cost_ out=want (drop=_name_);&lt;BR /&gt;by category product;&lt;BR /&gt;var cost;&lt;BR /&gt;id year;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Sep 2016 15:00:41 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-09-15T15:00:41Z</dc:date>
    <item>
      <title>reshape observations als variables ore viceversa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-observations-als-variables-ore-viceversa/m-p/298640#M62823</link>
      <description>&lt;P&gt;Dear experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following data sets:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA cost;&lt;BR /&gt;INPUT cost 4. category $2. product $4. year $4. ;&lt;BR /&gt;DATALINES;&lt;BR /&gt;061 1 ABC 2010&lt;BR /&gt;062 1 ABC 2011&lt;BR /&gt;067 1 ABC 2012&lt;BR /&gt;070 1 ABC 2013&lt;BR /&gt;100 1 DEF 2010&lt;BR /&gt;105 1 DEF 2011&lt;BR /&gt;050 2 GHI 2011&lt;BR /&gt;055 2 GHI 2012&lt;BR /&gt;060 2 GHI 2013&lt;BR /&gt;;run;&lt;/P&gt;&lt;P&gt;DATA revenues;&lt;BR /&gt;INPUT category $2. product $4. revenue_2010 4. revenue_2011 4. revenue_2012 4. revenue_2013 4. ;&lt;BR /&gt;DATALINES;&lt;BR /&gt;1 ABC 100 098 102 100&lt;BR /&gt;1 DEF 120 110 000 000&lt;BR /&gt;2 GHI 000 080 075 070&lt;BR /&gt;;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to calculate the difference between cost and revenues (it is an example, it is about how to do it not why) I need to reshape the both the tables in the same structure. I would like to reshape cost in the form of revenues and viceversal.&lt;/P&gt;&lt;P&gt;Any Ideas? I tried with poc mean, proc sql, proc transpose but I did not what I get in a authomatize, quick and elegant manne.&lt;/P&gt;&lt;P&gt;Thanks in advance for your reply.&lt;/P&gt;&lt;P&gt;BRs, SH&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 14:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-observations-als-variables-ore-viceversa/m-p/298640#M62823</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-09-15T14:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: reshape observations als variables ore viceversa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-observations-als-variables-ore-viceversa/m-p/298646#M62826</link>
      <description>&lt;P&gt;Since transforming the Revenue data makes more sense as far as matching up :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data revenuewant (keep= category product year revenue);
   set revenues;
   array r {2010:2013} revenue: ;
   do year= 2010 to 2013;
      revenue = r[year];
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Sep 2016 14:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-observations-als-variables-ore-viceversa/m-p/298646#M62826</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-15T14:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: reshape observations als variables ore viceversa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-observations-als-variables-ore-viceversa/m-p/298649#M62828</link>
      <description>&lt;P&gt;Well, the problem here, as with most problems, is the data structure of the second dataset. &amp;nbsp;Using "data" as columns headers always leads to problems, and lots of unmanagable code. Simply putting that data into a normalised data structure with fixed columns names, and the data in the data part makes the coding so much simpler:&lt;/P&gt;
&lt;PRE&gt;data cost;
  input cost 4. category $2. product $4. year $4. ;
datalines;
061 1 ABC 2010
062 1 ABC 2011
067 1 ABC 2012
070 1 ABC 2013
100 1 DEF 2010
105 1 DEF 2011
050 2 GHI 2011
055 2 GHI 2012
060 2 GHI 2013
;
run;
data revenues;
  input category $2. product $4. revenue_2010 4. revenue_2011 4. revenue_2012 4. revenue_2013 4. ;
datalines;
1 ABC 100 098 102 100
1 DEF 120 110 000 000
2 GHI 000 080 075 070
;
run;

proc transpose data=revenues out=t_revenues;
  by category product;
  var revenue:;
run;

data t_revenues;
  set t_revenues;
  year=scan(_name_,2,"_");
run;

proc sql;
  create table INTER as
  select  A.*,
          B.COST
  from    T_REVENUES A
  left join COST B
  on      A.CATEGORY=B.CATEGORY
  and     A.PRODUCT=B.PRODUCT
  and     A.YEAR=B.YEAR;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Sep 2016 14:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-observations-als-variables-ore-viceversa/m-p/298649#M62828</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-09-15T14:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: reshape observations als variables ore viceversa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-observations-als-variables-ore-viceversa/m-p/298650#M62829</link>
      <description>&lt;P&gt;I did that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=revenues out=revenues_1 prefix=revenue name=revyear;
by category product;
var _numeric_;
run;

data revenues_2;
set revenues_1 (rename=(revenue1=revenue));
length year $4;
year = substr(revyear,9);
drop revyear;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can run your analyses by category, product and year.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 14:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-observations-als-variables-ore-viceversa/m-p/298650#M62829</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-15T14:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: reshape observations als variables ore viceversa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-observations-als-variables-ore-viceversa/m-p/298669#M62840</link>
      <description>&lt;P&gt;On the one hand, I agree with those who contend that COST has the "right" structure and REVENUE has the "wrong" structure.&amp;nbsp; On the other hand, it's not for me to pre-judge the requirements that you will encounter in your future programming.&amp;nbsp; With that said, here is how you might transpose the COST data into the REVENUE structure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc transpose data=cost prefix=cost_ out=want (drop=_name_);&lt;BR /&gt;by category product;&lt;BR /&gt;var cost;&lt;BR /&gt;id year;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 15:00:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-observations-als-variables-ore-viceversa/m-p/298669#M62840</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-15T15:00:41Z</dc:date>
    </item>
  </channel>
</rss>

