<?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: transform the data in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/transform-the-data/m-p/896481#M82964</link>
    <description>&lt;P&gt;Seems like a simple application of using ARRAYs.&lt;/P&gt;
&lt;P&gt;Let's rename the original variables so we can use&amp;nbsp;revenue and profit as the names of the arrays.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until(last.id);
    set have(rename=(profit=_profit revenue=_revenue));
    by id;
    array profit [4];
    array revenue [4];
    profit[serial] = _profit;
    revenue[serial] = _revenue;
  end;
  drop serial _profit _revenue;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    id    profit1    profit2    profit3    profit4    revenue1    revenue2    revenue3    revenue4

 1      1       2          5          7          9          10          20          30          40
 2      2       3          8          .          .           5          10           .           .
&lt;/PRE&gt;</description>
    <pubDate>Fri, 29 Sep 2023 16:55:30 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-09-29T16:55:30Z</dc:date>
    <item>
      <title>transform the data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/transform-the-data/m-p/896474#M82963</link>
      <description>&lt;P&gt;i need the output as below,can anyone help me&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;
id profit1 profit2 profit3 profit4 revenue1 revenue2 revenue3 revenue4
1    2         5      7    9           10       20       30       40
2    3         8      .    .           3         8        .    
&lt;/LI-CODE&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data I have&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;
Data have;
input id serial Revenue profit;
cards;
1 1 10 2
1 2 20 5
1 3 30 7
1 4 40 9
2 1 5 3
2 2 10 8
2 3 . .
2 4 . .
;
Run;
proc print; run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 16:50:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/transform-the-data/m-p/896474#M82963</guid>
      <dc:creator>Pavani2</dc:creator>
      <dc:date>2023-09-29T16:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: transform the data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/transform-the-data/m-p/896481#M82964</link>
      <description>&lt;P&gt;Seems like a simple application of using ARRAYs.&lt;/P&gt;
&lt;P&gt;Let's rename the original variables so we can use&amp;nbsp;revenue and profit as the names of the arrays.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until(last.id);
    set have(rename=(profit=_profit revenue=_revenue));
    by id;
    array profit [4];
    array revenue [4];
    profit[serial] = _profit;
    revenue[serial] = _revenue;
  end;
  drop serial _profit _revenue;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    id    profit1    profit2    profit3    profit4    revenue1    revenue2    revenue3    revenue4

 1      1       2          5          7          9          10          20          30          40
 2      2       3          8          .          .           5          10           .           .
&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Sep 2023 16:55:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/transform-the-data/m-p/896481#M82964</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-29T16:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: transform the data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/transform-the-data/m-p/896504#M82965</link>
      <description>&lt;P&gt;Usually there is little benefit to transposing long to wide. If you want to create a report (as opposed to a SAS data set) in this wide format that you want, leave the data as it is in the long arrangement, and use PROC REPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=have;
    columns id profit,(" " serial) revenue,(" " serial) ;
    define id/group 'ID';
    define serial/across " ";
    define revenue/sum 'Revenue';
    define profit/sum 'Profit';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are plenty of formatting capabilites to make the above PROC REPORT output look nicer if needed.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 18:29:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/transform-the-data/m-p/896504#M82965</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-29T18:29:40Z</dc:date>
    </item>
  </channel>
</rss>

