<?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 from wide to long in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reshape-from-wide-to-long/m-p/304306#M64774</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input ID VAR_MALAYSIA :$32. VAR_USA :$32.;
datalines;
1 KUALA_LUMPUR CALIFORNIA
2 KELANTAN ALASKA
;
run;
proc transpose data=have out=transposed_have;
by ID;
var VAR_MALAYSIA VAR_USA;
run;

data want(DROP=_NAME_ RENAME=(COL1=STATE));
set transposed_have;
if _NAME_ = 'VAR_MALAYSIA' then COUNTRY='MALAYSIA' ;
if _NAME_ = 'VAR_USA' then COUNTRY='USA' ;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You need to work more on the last data step if there are many more countries.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Oct 2016 09:58:05 GMT</pubDate>
    <dc:creator>RahulG</dc:creator>
    <dc:date>2016-10-13T09:58:05Z</dc:date>
    <item>
      <title>Reshape from wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reshape-from-wide-to-long/m-p/304299#M64769</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'd like to know how can I create this "WANT" dataset from "HAVE". I couldn't find a way how to transpose.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;infile datalines truncover;&lt;BR /&gt;input ID VAR_MALAYSIA :$32. VAR_USA :$32.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 KUALA_LUMPUR CALIFORNIA&lt;BR /&gt;2 KELANTAN ALASKA&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;infile datalines truncover;&lt;BR /&gt;input ID COUNTRY :$32. STATE :$32.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 MALAYSIA KUALA_LUMPUR &lt;BR /&gt;1 USA CALIFORNIA&lt;BR /&gt;2 MALAYSIA KELANTAN&lt;BR /&gt;2 USA ALASKA&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 09:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reshape-from-wide-to-long/m-p/304299#M64769</guid>
      <dc:creator>angeliquec</dc:creator>
      <dc:date>2016-10-13T09:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: Reshape from wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reshape-from-wide-to-long/m-p/304305#M64773</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  infile datalines truncover;
  input id var_malaysia :$32. var_usa :$32.;
datalines;
1 KUALA_LUMPUR CALIFORNIA
2 KELANTAN ALASKA
;
run;

proc transpose data=have out=inter;
  by id;
  var var_malaysia var_usa;
run;

data want (keep=id country state);
  set inter;
  length country state $50;
  country=scan(_name_,2,"_");
  state=col1;
run;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Oct 2016 09:58:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reshape-from-wide-to-long/m-p/304305#M64773</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-13T09:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Reshape from wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reshape-from-wide-to-long/m-p/304306#M64774</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input ID VAR_MALAYSIA :$32. VAR_USA :$32.;
datalines;
1 KUALA_LUMPUR CALIFORNIA
2 KELANTAN ALASKA
;
run;
proc transpose data=have out=transposed_have;
by ID;
var VAR_MALAYSIA VAR_USA;
run;

data want(DROP=_NAME_ RENAME=(COL1=STATE));
set transposed_have;
if _NAME_ = 'VAR_MALAYSIA' then COUNTRY='MALAYSIA' ;
if _NAME_ = 'VAR_USA' then COUNTRY='USA' ;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You need to work more on the last data step if there are many more countries.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 09:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reshape-from-wide-to-long/m-p/304306#M64774</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-10-13T09:58:05Z</dc:date>
    </item>
  </channel>
</rss>

