<?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: How to reshape data? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357171#M83830</link>
    <description>&lt;P&gt;HI Ksharp your trip worked for but is there any way to name columns in want data as a, b, c. Please suggest me. &amp;nbsp;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 09 May 2017 13:16:34 GMT</pubDate>
    <dc:creator>ervinodsingh</dc:creator>
    <dc:date>2017-05-09T13:16:34Z</dc:date>
    <item>
      <title>How to reshape data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357132#M83817</link>
      <description>&lt;P&gt;Hi have data like&amp;nbsp;&lt;/P&gt;&lt;P&gt;a 4&lt;/P&gt;&lt;P&gt;a 3&lt;/P&gt;&lt;P&gt;a 6&lt;/P&gt;&lt;P&gt;b 3&lt;/P&gt;&lt;P&gt;b 7&lt;/P&gt;&lt;P&gt;b 8&lt;/P&gt;&lt;P&gt;c 1&lt;/P&gt;&lt;P&gt;c 5&lt;/P&gt;&lt;P&gt;c 7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and want my data to the form&amp;nbsp;&lt;/P&gt;&lt;P&gt;4 3 1&lt;/P&gt;&lt;P&gt;3 7 5&lt;/P&gt;&lt;P&gt;6 8 7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 11:31:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357132#M83817</guid>
      <dc:creator>ervinodsingh</dc:creator>
      <dc:date>2017-05-09T11:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to reshape data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357138#M83818</link>
      <description>&lt;P&gt;It really helps if you think of your data as variables and observations instead of matrices. Your input has two variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input varname $ value ;
cards;
a 4
a 3
a 6
b 3
b 7
b 8
c 1
c 5
c 7
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And your output data has three variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  input a b c ;
cards;
4 3 1
3 7 5
6 8 7
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What your input data is missing is anyway to tell explain why the observation should ahve A=4 and B=3 instead of say A=4 and B=7.&lt;/P&gt;
&lt;P&gt;If we assume you want to keep the values in the same relative order as in the source data then you just need to add a variable to your input data that you can use to group the observations. &amp;nbsp;So let's make a variable called GROUP.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data middle;
  set have ;
  by varname ;
  if first.varname then group=0;
  group +1;
run;
proc sort;
  by group varname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then we can make the desired output using PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=middle out=want ;
  by group;
  id varname ;
  var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2017 11:43:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357138#M83818</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-05-09T11:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to reshape data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357161#M83827</link>
      <description>&lt;P&gt;It is very easy for IML code.&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 id $ value;
cards;
a 4
a 3
a 6
b 3
b 7
b 8
c 1
c 5
c 7
;
run;
proc iml;
use have;
read all var{value};
close;
x=shapecol(value,3);

create want from x;
append from x;
close;
quit;

proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 12:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357161#M83827</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-09T12:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to reshape data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357171#M83830</link>
      <description>&lt;P&gt;HI Ksharp your trip worked for but is there any way to name columns in want data as a, b, c. Please suggest me. &amp;nbsp;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 13:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357171#M83830</guid>
      <dc:creator>ervinodsingh</dc:creator>
      <dc:date>2017-05-09T13:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to reshape data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357174#M83832</link>
      <description>&lt;P&gt;Sure. It is a piece of cake for IML.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ value;
cards;
a 4
a 3
a 6
b 3
b 7
b 8
c 1
c 5
c 7
;
run;
proc sort data=have;
 by id;
run;
proc iml;
use have;
read all var{id value};
close;
x=shapecol(value,3);
vname=unique(id);
create want from x[c=vname];
append from x;
close;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2017 13:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357174#M83832</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-09T13:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to reshape data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357177#M83834</link>
      <description>&lt;P&gt;Or the followng code could get you more slick.&lt;/P&gt;
&lt;P&gt;No need input 3 by hand .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ value;
cards;
a 4
a 3
a 6
b 3
b 7
b 8
c 1
c 5
c 7
;
run;
proc sql noprint;
select count(*) into : n from have group by id;
quit;

proc sort data=have;
 by id;
run;
proc iml;
use have;
read all var{id value};
close;
x=shapecol(value,&amp;amp;n);
vname=unique(id);
create want from x[c=vname];
append from x;
close;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2017 13:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357177#M83834</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-09T13:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to reshape data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357387#M83889</link>
      <description>&lt;P&gt;Thankyou Ksharp it worked for me like a charm.&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 07:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reshape-data/m-p/357387#M83889</guid>
      <dc:creator>ervinodsingh</dc:creator>
      <dc:date>2017-05-10T07:04:28Z</dc:date>
    </item>
  </channel>
</rss>

