<?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 Long to Wide in Enterprise Guide in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transpose-Long-to-Wide-in-Enterprise-Guide/m-p/639906#M190434</link>
    <description>&lt;P&gt;You can perform the reshaping with two TRANSPOSE steps with an intermediate DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input 
ID	FirstCount	FirstSales	SecondCount	SecondSales	ThirdCount	ThirdSales	FourthCount	FourthSales;
informat firstsales secondsales thirdsales fourthsales dollar12.;
  format firstsales secondsales thirdsales fourthsales dollar12.;
datalines;
1	23	 $156 	 25 	 $65,147 	89	 $215,654 	5	 $215 
2	38	 $107,964 	 17 	 $123,032 	0	 $-   	520	 $138,101 
3	0	 $-   	 -   	 $-   	151	 $514,785 	0	 $-   
;

proc transpose data=have out=stage1;
  by id;
run;

data stage2;
  set stage1;
  length type $27;
  type = prxchange('s/(count|sales)//i', 1, _name_);
  var = tranwrd(_name_, trim(type), '');
run;

proc transpose data=stage2 out=want(drop=_name_);
  by id type notsorted;
  id var;
  var col1;
  format sales dollar12.;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Similar process to revert to the original shape&lt;/P&gt;
&lt;PRE&gt;* and back again;

data have;
  set want;
run;

proc transpose data=have out=stage1;
  by id type notsorted;
run;

data stage2;
  set stage1;
  _newname_ = cats(type,_name_);
run;

proc transpose data=stage2 out=want(drop=_name_);
  by id;
  id _newname_;
run;
&lt;/PRE&gt;
&lt;P&gt;Note:&amp;nbsp; The OP image shows wide and long not consistent to question.&lt;/P&gt;
&lt;P&gt;In general, if you have &lt;STRONG&gt;tall&lt;/STRONG&gt; categorical data, a reshaping into the 'wide' shape the task is more a reporting issue than a data transformation issue.&amp;nbsp; Proc TABULATE or REPORT are great for presenting the categorical data in any desired shape.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ods html file='wide.html';
proc tabulate data=tall;
  class id type / order=data;
  var count sales;
  table id='', type='' * (count*sum=''*format=8. sales*sum=''*format=dollar12.) / box='ID';
run;

proc report data=tall;
  column id type,(count sales);
  define id/group;
  define type/across order=data;
run;

ods html close;&lt;/PRE&gt;</description>
    <pubDate>Tue, 14 Apr 2020 22:41:41 GMT</pubDate>
    <dc:creator>RichardDeVen</dc:creator>
    <dc:date>2020-04-14T22:41:41Z</dc:date>
    <item>
      <title>Transpose Long to Wide in Enterprise Guide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-Long-to-Wide-in-Enterprise-Guide/m-p/639897#M190431</link>
      <description>&lt;P&gt;Hello -&lt;/P&gt;&lt;P&gt;I am working with SAS EG, and my data looks like the data in the file as long. I need to convert that data into wide as in the file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you, and stay safe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 21:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-Long-to-Wide-in-Enterprise-Guide/m-p/639897#M190431</guid>
      <dc:creator>altijani</dc:creator>
      <dc:date>2020-04-14T21:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose Long to Wide in Enterprise Guide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-Long-to-Wide-in-Enterprise-Guide/m-p/639906#M190434</link>
      <description>&lt;P&gt;You can perform the reshaping with two TRANSPOSE steps with an intermediate DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input 
ID	FirstCount	FirstSales	SecondCount	SecondSales	ThirdCount	ThirdSales	FourthCount	FourthSales;
informat firstsales secondsales thirdsales fourthsales dollar12.;
  format firstsales secondsales thirdsales fourthsales dollar12.;
datalines;
1	23	 $156 	 25 	 $65,147 	89	 $215,654 	5	 $215 
2	38	 $107,964 	 17 	 $123,032 	0	 $-   	520	 $138,101 
3	0	 $-   	 -   	 $-   	151	 $514,785 	0	 $-   
;

proc transpose data=have out=stage1;
  by id;
run;

data stage2;
  set stage1;
  length type $27;
  type = prxchange('s/(count|sales)//i', 1, _name_);
  var = tranwrd(_name_, trim(type), '');
run;

proc transpose data=stage2 out=want(drop=_name_);
  by id type notsorted;
  id var;
  var col1;
  format sales dollar12.;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Similar process to revert to the original shape&lt;/P&gt;
&lt;PRE&gt;* and back again;

data have;
  set want;
run;

proc transpose data=have out=stage1;
  by id type notsorted;
run;

data stage2;
  set stage1;
  _newname_ = cats(type,_name_);
run;

proc transpose data=stage2 out=want(drop=_name_);
  by id;
  id _newname_;
run;
&lt;/PRE&gt;
&lt;P&gt;Note:&amp;nbsp; The OP image shows wide and long not consistent to question.&lt;/P&gt;
&lt;P&gt;In general, if you have &lt;STRONG&gt;tall&lt;/STRONG&gt; categorical data, a reshaping into the 'wide' shape the task is more a reporting issue than a data transformation issue.&amp;nbsp; Proc TABULATE or REPORT are great for presenting the categorical data in any desired shape.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ods html file='wide.html';
proc tabulate data=tall;
  class id type / order=data;
  var count sales;
  table id='', type='' * (count*sum=''*format=8. sales*sum=''*format=dollar12.) / box='ID';
run;

proc report data=tall;
  column id type,(count sales);
  define id/group;
  define type/across order=data;
run;

ods html close;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Apr 2020 22:41:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-Long-to-Wide-in-Enterprise-Guide/m-p/639906#M190434</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-04-14T22:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose Long to Wide in Enterprise Guide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-Long-to-Wide-in-Enterprise-Guide/m-p/639907#M190435</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;My data is currently long as in your second code. I need it to be as in your first shape.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 21:56:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-Long-to-Wide-in-Enterprise-Guide/m-p/639907#M190435</guid>
      <dc:creator>altijani</dc:creator>
      <dc:date>2020-04-14T21:56:24Z</dc:date>
    </item>
  </channel>
</rss>

