<?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 Wide Field to Long in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reshape-Wide-Field-to-Long/m-p/388391#M93151</link>
    <description>&lt;P&gt;Another possible solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input num code $;
cards;
1 A,B
2 C,D
;
run;

Data Want;
  Set have;
  Col_1 = Scan(code, 1, ",");
  Col_2 = Scan(code, 2, ",");
  Drop code;
Run;

Proc Transpose Data = Want 
		       Out = Want (Rename=(Col1=code) Drop=_NAME_);
  By num;
  Var Col_1 Col_2; 
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 16 Aug 2017 08:51:23 GMT</pubDate>
    <dc:creator>user24feb</dc:creator>
    <dc:date>2017-08-16T08:51:23Z</dc:date>
    <item>
      <title>Reshape Wide Field to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reshape-Wide-Field-to-Long/m-p/388372#M93141</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need help to produce the WANT dataset from my HAVE dataset.&lt;/P&gt;
&lt;P&gt;data want; &lt;BR /&gt;input num code $;&lt;BR /&gt;cards;&lt;BR /&gt;1 A&lt;BR /&gt;1 B&lt;BR /&gt;2 C&lt;BR /&gt;2 D&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data HAVE; &lt;BR /&gt;input num code $;&lt;BR /&gt;cards;&lt;BR /&gt;1 A,B&lt;BR /&gt;2 C,D&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 06:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reshape-Wide-Field-to-Long/m-p/388372#M93141</guid>
      <dc:creator>angeliquec</dc:creator>
      <dc:date>2017-08-16T06:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: Reshape Wide Field to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reshape-Wide-Field-to-Long/m-p/388377#M93144</link>
      <description>&lt;P&gt;With a data step and by group processing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input num code $;
cards;
1 A
1 B
2 C
2 D
;
run;

data want;
set have (rename=(code=_code));
by num;
retain code "              "; * make long enough to hold all values;
if first.num then code = '';
code = catx(',',code,_code);
if last.num then output;
drop _code;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;num    code

 1     A,B 
 2     C,D &lt;/PRE&gt;
&lt;P&gt;Correct order of dataset have by num is required.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 06:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reshape-Wide-Field-to-Long/m-p/388377#M93144</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-16T06:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Reshape Wide Field to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reshape-Wide-Field-to-Long/m-p/388391#M93151</link>
      <description>&lt;P&gt;Another possible solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input num code $;
cards;
1 A,B
2 C,D
;
run;

Data Want;
  Set have;
  Col_1 = Scan(code, 1, ",");
  Col_2 = Scan(code, 2, ",");
  Drop code;
Run;

Proc Transpose Data = Want 
		       Out = Want (Rename=(Col1=code) Drop=_NAME_);
  By num;
  Var Col_1 Col_2; 
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Aug 2017 08:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reshape-Wide-Field-to-Long/m-p/388391#M93151</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2017-08-16T08:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Reshape Wide Field to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reshape-Wide-Field-to-Long/m-p/388591#M93196</link>
      <description>No need to use proc transpose. A loop with an output-statement will do:&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;fullCode = code;&lt;BR /&gt;do i = 1 to countw(fullCode, ",");&lt;BR /&gt;code = scan(fullCode, i, ",");&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;drop i fullCode;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 16 Aug 2017 19:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reshape-Wide-Field-to-Long/m-p/388591#M93196</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-08-16T19:51:52Z</dc:date>
    </item>
  </channel>
</rss>

