<?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: Long to Wide in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide/m-p/69679#M15106</link>
    <description>Thanks Patrick. This is what I was exactly looking for...</description>
    <pubDate>Mon, 22 Mar 2010 13:31:40 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-03-22T13:31:40Z</dc:date>
    <item>
      <title>Long to Wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide/m-p/69676#M15103</link>
      <description>Hi, &lt;BR /&gt;
I have a dataset in the following format&lt;BR /&gt;
&lt;BR /&gt;
ID   Vi    PID  Complete     Notes&lt;BR /&gt;
100  1    29         1            good&lt;BR /&gt;
100  2    34         0            early &lt;BR /&gt;
101  2    29         1&lt;BR /&gt;
101  3    32         0              bad&lt;BR /&gt;
&lt;BR /&gt;
I want this to be formatted to &lt;BR /&gt;
&lt;BR /&gt;
ID   VI    com_29  Note_29   Com_32  Note_32   Com_34   Note_34  &lt;BR /&gt;
100  1       1           good         .              .              .                .&lt;BR /&gt;
100  2        .             .             .              .               1            early&lt;BR /&gt;
101  2        1             .            .               .               .               .&lt;BR /&gt;
101  3        .              .            0             bad            .                .&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I'm currently here at my code;&lt;BR /&gt;
&lt;BR /&gt;
data have1; &lt;BR /&gt;
set a; &lt;BR /&gt;
by id vi pid; &lt;BR /&gt;
if first.id then line=0;&lt;BR /&gt;
if first.pid then line+1;&lt;BR /&gt;
varname = cats(pid,'_',line); &lt;BR /&gt;
varname1 = cats(pid,'__',line); &lt;BR /&gt;
run; &lt;BR /&gt;
proc transpose data=have1 out=want1; &lt;BR /&gt;
by id vi; &lt;BR /&gt;
id varname; &lt;BR /&gt;
var complete; &lt;BR /&gt;
run; &lt;BR /&gt;
proc transpose data=have1 out=want2; &lt;BR /&gt;
by id vi; &lt;BR /&gt;
id varname1; &lt;BR /&gt;
var notes; &lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
proc sort data=want1;by id vi;Run;&lt;BR /&gt;
proc sort data=want2;by id vi;Run;&lt;BR /&gt;
&lt;BR /&gt;
data merge1;merge want1(in=x) want2(in=y);by id vi;if x and y;Run;&lt;BR /&gt;
&lt;BR /&gt;
But since I'm keeping the count in the line variable for appeding it to the column name later, if a same person get a repeated PID value in a different visit the count is not the same, for example&lt;BR /&gt;
&lt;BR /&gt;
ID  VI   PID  COMPLETE   NOTES&lt;BR /&gt;
100  1   29      1                  &lt;BR /&gt;
100  1   32       0&lt;BR /&gt;
100   2   29      1 &lt;BR /&gt;
&lt;BR /&gt;
then my have1 dataset will have  this varnames values which makes the want1 dataset to have two rows because of repeated 29_1 variable . So I need to stop the count at the last occurrence of the ID Vi and start a fresh count.Any help in here?&lt;BR /&gt;
&lt;BR /&gt;
100   1    29_1&lt;BR /&gt;
100   1    32_2&lt;BR /&gt;
100   2     29_1&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your time.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
MAtt</description>
      <pubDate>Fri, 19 Mar 2010 18:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide/m-p/69676#M15103</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-19T18:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: Long to Wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide/m-p/69677#M15104</link>
      <description>Not sure if this is exactly what you want  but this may help&lt;BR /&gt;
&lt;BR /&gt;
proc sort data = a nodup; by ID VI PID;&lt;BR /&gt;
Data b (Keep = ID VI COM_29 Note_29 Com_32 Note_32 Com_34 Note_34);&lt;BR /&gt;
 attrib id vi length = 8&lt;BR /&gt;
        Com_29 length = 8&lt;BR /&gt;
		 Note_29 length= $8&lt;BR /&gt;
        Com_32 length =8&lt;BR /&gt;
		 Note_32 length= $8&lt;BR /&gt;
        Com_34 length= 8&lt;BR /&gt;
         Note_34 length= $8&lt;BR /&gt;
	;&lt;BR /&gt;
 &lt;BR /&gt;
 array com  (3)   Com_29 Com_32 Com_34;&lt;BR /&gt;
 array note (3)$  Note_29 Note_32  Note_34; &lt;BR /&gt;
 do c = 1 to 3;&lt;BR /&gt;
   set a;&lt;BR /&gt;
   by ID VI;&lt;BR /&gt;
     Select (PID);&lt;BR /&gt;
	   when (29) do; com(1) = Complete; note(1) = Notes; end;&lt;BR /&gt;
	   when (32) do; com(2) = Complete; note(2) = Notes; end;&lt;BR /&gt;
	   when (34) do; com(3) = complete; note(3) = Notes; end;&lt;BR /&gt;
	   otherwise;&lt;BR /&gt;
	 end;&lt;BR /&gt;
   if last.vi then return;&lt;BR /&gt;
 end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I included the attrib statement so that the order stays the same as in your example.  You may have to get  a bit more creative if you have more than the 3pairs of columns.</description>
      <pubDate>Fri, 19 Mar 2010 20:53:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide/m-p/69677#M15104</guid>
      <dc:creator>LAP</dc:creator>
      <dc:date>2010-03-19T20:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: Long to Wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide/m-p/69678#M15105</link>
      <description>Hi Matt&lt;BR /&gt;
&lt;BR /&gt;
I believe the code below does what you asked for.&lt;BR /&gt;
&lt;BR /&gt;
If I understand this right then you were very close and only missed the possibilities of the "copy" statement in "proc transpose".&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
infile datalines truncover;&lt;BR /&gt;
input ID Vi PID Complete Notes $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
100 1 29 1 good&lt;BR /&gt;
100 2 34 0 early &lt;BR /&gt;
101 2 29 1&lt;BR /&gt;
101 3 32 0 bad&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc transpose data=have out=pre_want(drop=_name_) prefix=Com_;&lt;BR /&gt;
  by id vi;&lt;BR /&gt;
  id pid;&lt;BR /&gt;
  var Complete;&lt;BR /&gt;
  copy pid Notes;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc transpose data=pre_want out=want(drop=_name_)  prefix=Note_;&lt;BR /&gt;
  by id vi;&lt;BR /&gt;
  id pid;&lt;BR /&gt;
  var Notes;&lt;BR /&gt;
  copy Com_:;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=want noobs;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Sat, 20 Mar 2010 00:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide/m-p/69678#M15105</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-03-20T00:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Long to Wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide/m-p/69679#M15106</link>
      <description>Thanks Patrick. This is what I was exactly looking for...</description>
      <pubDate>Mon, 22 Mar 2010 13:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide/m-p/69679#M15106</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-22T13:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Long to Wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide/m-p/69680#M15107</link>
      <description>Thanks...</description>
      <pubDate>Mon, 22 Mar 2010 13:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide/m-p/69680#M15107</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-22T13:32:00Z</dc:date>
    </item>
  </channel>
</rss>

