<?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 data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469477#M120107</link>
    <description>&lt;P&gt;I think there are something wrong with the code. I didn't pay attention to the testing data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result is that the number is always 0&amp;nbsp; or 1. If you use the following testing data, you will still get number is o or 1. Even there should be two moved from a to b from 2000 to 2001.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input city2000 $ city2001 $ city2002 $ city2003 $;
datalines;
a b b c
a b a a
b a a a
c c c c
c a a a
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Jun 2018 00:46:26 GMT</pubDate>
    <dc:creator>saseles</dc:creator>
    <dc:date>2018-06-12T00:46:26Z</dc:date>
    <item>
      <title>reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469412#M120071</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;I have a data set as following: (real data have more years and locations)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data have;
input city2000 $ city2001 $ city2002 $ city2003 $;
datalines;
a a b c
a a a a
b a a a
c c c c
c a a a
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to have a data which tracks the movement between all possible pairs of cities by year. So, the result will be alike below. Note that it doesn't include the city pair of itself, but if i want to include pairs like a - a, b - c, c - c. Is that easy to modify code?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data want;
input from $ to $ year number;
datalines;
a b 2001 0
a c 2001 0
b a 2001 1
b c 2001 0
c a 2001 1
c b 2001 0
a b 2002 1
a c 2002 0
b a 2002 0
b c 2002 0
c a 2002 0
c b 2002 0
a b 2003 0
a c 2003 0
b a 2003 0
b c 2003 1
c a 2003 0
c b 2003 0
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks for any help!&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 21:29:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469412#M120071</guid>
      <dc:creator>saseles</dc:creator>
      <dc:date>2018-06-11T21:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469423#M120077</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214649"&gt;@saseles&lt;/a&gt;&amp;nbsp;Your requirement seems very similar to this thread&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/construct-my-own-data-sets-from-two-source-data-sets/m-p/468954#M119846" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/construct-my-own-data-sets-from-two-source-data-sets/m-p/468954#M119846&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please review and see if you are able to modify to your needs?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 22:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469423#M120077</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-11T22:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469426#M120078</link>
      <description>&lt;P&gt;Hello novinosrin:&lt;/P&gt;&lt;P&gt;I can tell the similarity. But i am don't understand the data old_2. Seems that i only have old_1. I don't know how to modify the code since there are some commend are really new to me.&lt;/P&gt;&lt;P&gt;Any suggestions?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 22:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469426#M120078</guid>
      <dc:creator>saseles</dc:creator>
      <dc:date>2018-06-11T22:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469432#M120081</link>
      <description>&lt;P&gt;Here is what i tried. But not sure it is right or not. Can you please verify it?&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data have;
input city2000 $ city2001 $ city2002 $ city2003 $;
datalines;
a a b c
a a a a
b a a a
c c c c
c a a a
;

data _null_;
if _n_=1 then do;
if 0 then set have;
length o d $50;
  dcl hash H1 (multidata:'y',ordered:'y') ;
   h1.definekey  ('year','o','d') ;
   h1.definedata ('year',"o","d") ;
   h1.definedone () ;
   call missing(o,d);
end;
set have end=last;
array t(*) pc:;
do _n_= 2 to dim(t);
year=vname(t(_n_));
o=t(_n_-1);
d=t(_n_);
rc=h1.add();
end;
if last then h1.output(dataset:'temp2');
run;

data want;
if _n_=1 then do;
if 0 then set temp3;
  dcl hash H1 (dataset:'temp3',multidata:'y') ;
   h1.definekey  ('year','o','d') ;
   h1.definedata ('flows') ;
   h1.definedone () ;
end;
if 0 then set old_1;
array t(*) pc:;
set sort_2(rename=(region=o));
do _n_= 2 to dim(t);
year=vname(t(_n_));
 do n=1 to nobs;
 set sort_2(keep=region rename=(region=d)) nobs=nobs point=n;
flows=0;
rc= h1.find();
 output;
end;
end;
keep year o d flows;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jun 2018 22:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469432#M120081</guid>
      <dc:creator>saseles</dc:creator>
      <dc:date>2018-06-11T22:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469435#M120083</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214649"&gt;@saseles&lt;/a&gt;&amp;nbsp;Oh no worries, I will work on the code for you shortly. But did you look at the &lt;EM&gt;&lt;STRONG&gt;other accepted solution&lt;/STRONG&gt; &lt;/EM&gt;that doesn't use hashes, which I believe is easier to follow step by step. If not, try to read&amp;nbsp; through it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And mine does require some cleaning anyways. lol&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 22:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469435#M120083</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-11T22:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469436#M120084</link>
      <description>&lt;P&gt;I tried that one as well. It seems that my problem is easier than that one since I don't need to merge those two data sets. I just got problem to modify the code&amp;nbsp;&lt;img id="manindifferent" class="emoticon emoticon-manindifferent" src="https://communities.sas.com/i/smilies/16x16_man-indifferent.png" alt="Man Indifferent" title="Man Indifferent" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 22:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469436#M120084</guid>
      <dc:creator>saseles</dc:creator>
      <dc:date>2018-06-11T22:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469440#M120088</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214649"&gt;@saseles&lt;/a&gt;&amp;nbsp; Here you go. Have fun&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit:&amp;nbsp; Adding one more step to get the order right&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 city2000 $ city2001 $ city2002 $ city2003 $;
datalines;
a a b c
a a a a
b a a a
c c c c
c a a a
;

data temp;
set have end=last;
array t(*) city:;
do _n_= 2 to dim(t);
year=vname(t(_n_));
from=t(_n_-1);
to=t(_n_);
output;
end;
drop city:;
run;
proc transpose data=have out=t(keep=col1);
by city: notsorted;
var city:;
run;

proc sort data=t nodupkey;
by col1;
run;
data want;
if _n_=1 then do;
 dcl hash H1 (dataset:'temp',multidata:'y') ;
   h1.definekey  ('year','from','to') ;
   h1.definedone () ;
end;
if 0 then set have;
array t(*) city:;
set t(rename=(col1=from));
do _n_= 2 to dim(t);
year=vname(t(_n_));
do n=1 to nobs ;
set t(rename=(col1=to)) nobs=nobs point=n;
if to ne from then do;
if h1.check()=0 then number=1;
else number=0;
output;
end;
end;
end;
keep from year to number;
run;

proc sort data=want out=final_want;
by year;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 22:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469440#M120088</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-11T22:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469451#M120089</link>
      <description>&lt;P&gt;Thanks a lot! i am almost there!&lt;/P&gt;&lt;P&gt;The problem is that I have large data that cannot use the SAS work library. So, my data is save in my own defined library, say "mydata.have". I modified your code to direct all temp data to my library. But i don't know how to handle the third line in "data want" statement. i.e. "dcl hash H1 (dataset:'temp',multidata:'y') ;" . How to modify the one " ...dataset:'temp' ..." ?&lt;/P&gt;&lt;P&gt;I hope this is the final step.&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 23:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469451#M120089</guid>
      <dc:creator>saseles</dc:creator>
      <dc:date>2018-06-11T23:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469452#M120090</link>
      <description>&lt;P&gt;Do you mean to reference&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"dcl hash H1 (dataset:'temp',multidata:'y') ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"dcl hash H1 (datase&lt;EM&gt;&lt;STRONG&gt;t:'mydata.temp'&lt;/STRONG&gt;&lt;/EM&gt;,multidata:'y') ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If everything points to perm library just use the two level ref name like you did for others&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 23:17:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469452#M120090</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-11T23:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469453#M120091</link>
      <description>&lt;P&gt;I tried using ".... 'mydata.temp' ....", but I got error that "Hash object added XXXXXX items when memory failure occurred" "Insufficient memory to execute data step ...."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is something that related to my computer, not the code? I notice that the temp data has really large size. It is much larger then my original data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 23:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469453#M120091</guid>
      <dc:creator>saseles</dc:creator>
      <dc:date>2018-06-11T23:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469454#M120092</link>
      <description>&lt;P&gt;Oh gosh,&amp;nbsp;&lt;SPAN&gt;memory failure occurred" "Insufficient memory to execute data step ...."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;hash doesn't do well if you have&amp;nbsp;Insufficient memory mate.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I may have to change the code for you. Can you confirm&amp;nbsp; this before I modify again?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 23:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469454#M120092</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-11T23:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469457#M120095</link>
      <description>&lt;P&gt;I tried again. Same thing&amp;nbsp;&lt;img id="manindifferent" class="emoticon emoticon-manindifferent" src="https://communities.sas.com/i/smilies/16x16_man-indifferent.png" alt="Man Indifferent" title="Man Indifferent" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 23:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469457#M120095</guid>
      <dc:creator>saseles</dc:creator>
      <dc:date>2018-06-11T23:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469458#M120096</link>
      <description>&lt;P&gt;Ok no worries. Brb in 10 mins&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 23:31:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469458#M120096</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-11T23:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469461#M120097</link>
      <description>&lt;P&gt;Try this:&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 city2000 $ city2001 $ city2002 $ city2003 $;
datalines;
a a b c
a a a a
b a a a
c c c c
c a a a
;

data temp;
set have end=last;
array t(*) city:;
do _n_= 2 to dim(t);
year=vname(t(_n_));
from=t(_n_-1);
to=t(_n_);
output;
end;
drop city:;
run;
proc transpose data=have out=t(keep=col1);
by city: notsorted;
var city:;
run;

proc sort data=t nodupkey;
by col1;
run;

data want;
if 0 then set have;
array t(*) city:;
set t(rename=(col1=from));
do _n_= 2 to dim(t);
year=vname(t(_n_));
do n=1 to nobs ;
set t(rename=(col1=to)) nobs=nobs point=n;
if to ne from then output;
end;
end;
keep from year to ;
run;

proc sql;
create table final_want as
select *, 1 as Number from
 (select year,from,to from want
   intersect
   select year,from,to  from temp)
     union
select *,0 as Number
  from (select year,from,to  from want
         except
      select year,from,to  from temp)
order by year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jun 2018 23:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469461#M120097</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-11T23:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469467#M120101</link>
      <description>&lt;P&gt;where is the data "t" ? Do i need to run some other codes?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 23:59:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469467#M120101</guid>
      <dc:creator>saseles</dc:creator>
      <dc:date>2018-06-11T23:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469469#M120102</link>
      <description>&lt;P&gt;Please &lt;EM&gt;&lt;STRONG&gt;follow&lt;/STRONG&gt; &lt;/EM&gt;the script carefully and diligently and the only script above (the latest)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;t is from this step&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;transpose&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;have out&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;t&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;keep&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;col1&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; city: notsorted&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt; city:&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sort&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;t nodupkey&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; col1&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 00:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469469#M120102</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-12T00:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469472#M120103</link>
      <description>&lt;P&gt;Trying now!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 00:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469472#M120103</guid>
      <dc:creator>saseles</dc:creator>
      <dc:date>2018-06-12T00:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469474#M120104</link>
      <description>&lt;P&gt;Emmmm... not sure what happened....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works in my short testing data. But not working on real data. error: Ambiguous reference, column year is in more than one table ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I compared the two results. It seems working on my real data until the last proc sql. The data want looks good. But i got the above error from proc sql, and there is no final_want generated.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 00:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469474#M120104</guid>
      <dc:creator>saseles</dc:creator>
      <dc:date>2018-06-12T00:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469475#M120105</link>
      <description>&lt;P&gt;Oh, sorry, ignore my previous post. I found a typo in my code from adding my own library path. Give it a new try.&amp;nbsp;finger crossed!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 00:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469475#M120105</guid>
      <dc:creator>saseles</dc:creator>
      <dc:date>2018-06-12T00:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: reshape data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469476#M120106</link>
      <description>&lt;P&gt;Or&amp;nbsp; another option &lt;EM&gt;&lt;STRONG&gt;without sql using merge,&lt;/STRONG&gt;&lt;/EM&gt; notice the steps after temp and want&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input city2000 $ city2001 $ city2002 $ city2003 $;
datalines;
a a b c
a a a a
b a a a
c c c c
c a a a
;

data temp;
set have end=last;
array t(*) city:;
do _n_= 2 to dim(t);
year=vname(t(_n_));
from=t(_n_-1);
to=t(_n_);
output;
end;
drop city:;
run;
proc transpose data=have out=t(keep=col1);
by city: notsorted;
var city:;
run;

proc sort data=t nodupkey;
by col1;
run;

data want;
if 0 then set have;
array t(*) city:;
set t(rename=(col1=from));
do _n_= 2 to dim(t);
year=vname(t(_n_));
do n=1 to nobs ;
set t(rename=(col1=to)) nobs=nobs point=n;
if to ne from then output;
end;
end;
keep from year to ;
run;


proc sort data=want;
by  year from to;;
run;
proc sort data=temp;
by  year from to;
run;



data final_want;
merge want(in=a)  temp(in=b);
by  year from to;
if a;
if a and b then Number=1;
else NUmber=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Jun 2018 00:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reshape-data/m-p/469476#M120106</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-12T00:40:32Z</dc:date>
    </item>
  </channel>
</rss>

