<?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 transpose this in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60048#M17005</link>
    <description>Thank you soooooo much!</description>
    <pubDate>Fri, 07 Jan 2011 13:48:32 GMT</pubDate>
    <dc:creator>odmhx</dc:creator>
    <dc:date>2011-01-07T13:48:32Z</dc:date>
    <item>
      <title>how to transpose this</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60040#M16997</link>
      <description>I have the following data that I want to transpose, but tried and failed using proc transpose. &lt;BR /&gt;
&lt;BR /&gt;
input data:&lt;BR /&gt;
ProvID Company   Rate   Payment&lt;BR /&gt;
1234    CompA      20.2   100.00&lt;BR /&gt;
1234    CompA      30.5    200.00&lt;BR /&gt;
1234    CompA      40.7    300.00&lt;BR /&gt;
1234    CompB      20.2    150.00&lt;BR /&gt;
1234    CompB      50.5     250.00&lt;BR /&gt;
&lt;BR /&gt;
Intended output:&lt;BR /&gt;
&lt;BR /&gt;
ProvID Company Rate1 Payment1 Rate2 Payment2 Rate3 Payment3&lt;BR /&gt;
1234    CompA    20.2   100.00      30.5     200.00      40.7    300.00&lt;BR /&gt;
1234    CompB    20.2    150.00     50.5     250.00&lt;BR /&gt;
&lt;BR /&gt;
Can you help?</description>
      <pubDate>Thu, 06 Jan 2011 21:18:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60040#M16997</guid>
      <dc:creator>odmhx</dc:creator>
      <dc:date>2011-01-06T21:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose this</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60041#M16998</link>
      <description>There two way to do this.&lt;BR /&gt;
&lt;BR /&gt;
Using proc transpose&lt;BR /&gt;
&lt;BR /&gt;
proc transpose data=test out=trans;&lt;BR /&gt;
  by PROVID Company;&lt;BR /&gt;
  var Rate Payment;&lt;BR /&gt;
  run;&lt;BR /&gt;
&lt;BR /&gt;
Data final;&lt;BR /&gt;
  drop _name_;&lt;BR /&gt;
  merge trans (where=(_name_ = "Rate") &lt;BR /&gt;
               rename = (col1 = Rate1 &lt;BR /&gt;
                         col2=Rate2 col3 = Rate3))&lt;BR /&gt;
            trans (where=(_name_ = "Payment")&lt;BR /&gt;
                   rename = (col1 = Payment1    &lt;BR /&gt;
                             col2=Payment2 &lt;BR /&gt;
                             col3 = Payment3));&lt;BR /&gt;
  by provID company;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Alternately, you could do this in a data step.  I usually do this when there are a lot of rename statements.&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=example; &lt;BR /&gt;
data alternate (keep = provID company rate1-rate3 payment1-payment3);&lt;BR /&gt;
  array r(*) rate1 - rate3;&lt;BR /&gt;
  array p(*) payment1-payment3;&lt;BR /&gt;
&lt;BR /&gt;
  do i = 1 to 3;&lt;BR /&gt;
    set example;&lt;BR /&gt;
	by provID company;&lt;BR /&gt;
	r(i) = rate;&lt;BR /&gt;
	p(i) = payment;&lt;BR /&gt;
	if last.company then return;&lt;BR /&gt;
  end;&lt;BR /&gt;
  run;</description>
      <pubDate>Thu, 06 Jan 2011 22:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60041#M16998</guid>
      <dc:creator>LAP</dc:creator>
      <dc:date>2011-01-06T22:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose this</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60042#M16999</link>
      <description>Another way...&lt;BR /&gt;
&lt;BR /&gt;
data foo;&lt;BR /&gt;
 length Company $ 20;&lt;BR /&gt;
 input ProvID Company Rate Payment;&lt;BR /&gt;
 cards;&lt;BR /&gt;
1234 CompA 20.2 100.00&lt;BR /&gt;
1234 CompA 30.5 200.00&lt;BR /&gt;
1234 CompA 40.7 300.00&lt;BR /&gt;
1234 CompB 20.2 150.00&lt;BR /&gt;
1234 CompB 50.5 250.00&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/*&lt;BR /&gt;
proc sort data=foo;&lt;BR /&gt;
 by ProvID Company;&lt;BR /&gt;
run;&lt;BR /&gt;
*/&lt;BR /&gt;
&lt;BR /&gt;
data foo;&lt;BR /&gt;
 set foo;&lt;BR /&gt;
&lt;BR /&gt;
 by ProvID Company;&lt;BR /&gt;
&lt;BR /&gt;
 if first.Company &lt;BR /&gt;
 then i = 1;&lt;BR /&gt;
 else i = i + 1;&lt;BR /&gt;
&lt;BR /&gt;
 retain i;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc transpose data=foo out=bar1 PREFIX=RATE;&lt;BR /&gt;
 by ProvID Company;&lt;BR /&gt;
 id i;&lt;BR /&gt;
 var Rate;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc transpose data=foo out=bar2 PREFIX=PAYMENT;&lt;BR /&gt;
 by ProvID Company;&lt;BR /&gt;
 id i;&lt;BR /&gt;
 var Payment;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data bar;&lt;BR /&gt;
 merge bar1(drop=_NAME_) bar2(drop=_NAME_);&lt;BR /&gt;
 by ProvID Company;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=bar;&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 06 Jan 2011 23:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60042#M16999</guid>
      <dc:creator>scmebu</dc:creator>
      <dc:date>2011-01-06T23:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose this</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60043#M17000</link>
      <description>While what you want CAN be done with proc transpose, I typically prefer using proc summary to accomplish the task.  You can avoid the proc sql code, below, if you know that maximum number of rate/payments that you'll confront.  It is only included to count them:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
  input ProvID Company $ Rate Payment;&lt;BR /&gt;
  cards;&lt;BR /&gt;
1234 CompA 20.2 100.00&lt;BR /&gt;
1234 CompA 30.5 200.00&lt;BR /&gt;
1234 CompA 40.7 300.00&lt;BR /&gt;
1234 CompB 20.2 150.00&lt;BR /&gt;
1234 CompB 50.5 250.00&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* Get magic number;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
  select max(obs) into :obs&lt;BR /&gt;
    from (select count(*) as obs&lt;BR /&gt;
      from have&lt;BR /&gt;
        group by ProvID,Company)&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
* transpose to wide;&lt;BR /&gt;
proc summary nway data=have missing;&lt;BR /&gt;
  class ProvID Company;&lt;BR /&gt;
  output&lt;BR /&gt;
  out = want(drop=_type_ _freq_)&lt;BR /&gt;
  idgroup(out[&amp;amp;obs](Rate Payment)=)&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
      <pubDate>Thu, 06 Jan 2011 23:29:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60043#M17000</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-01-06T23:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose this</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60044#M17001</link>
      <description>WOW.Art T&lt;BR /&gt;
I bet that Art Carpenter will definitely like your code.&lt;BR /&gt;
My code is only another choice.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data have;&lt;BR /&gt;
input ProvID Company $ Rate Payment;&lt;BR /&gt;
cards;&lt;BR /&gt;
1234 CompA 20.2 100.00&lt;BR /&gt;
1234 CompA 30.5 200.00&lt;BR /&gt;
1234 CompA 40.7 300.00&lt;BR /&gt;
1234 CompB 20.2 150.00&lt;BR /&gt;
1234 CompB 50.5 250.00&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
* Get magic number;&lt;BR /&gt;
proc freq data=have noprint order=freq ;&lt;BR /&gt;
 tables provid*company /list out=count ;&lt;BR /&gt;
run;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
 set count;&lt;BR /&gt;
 if _n_ = 1 then do; call symputx('count',count); stop; end;&lt;BR /&gt;
run; &lt;BR /&gt;
* transpose to wide;&lt;BR /&gt;
proc sort data=have;&lt;BR /&gt;
 by provid company;&lt;BR /&gt;
run;&lt;BR /&gt;
data result(drop=rate payment i);&lt;BR /&gt;
 set have;&lt;BR /&gt;
 by provid company;&lt;BR /&gt;
 array r{*} rate1-rate&amp;amp;count;&lt;BR /&gt;
 array p{*} payment1-payment&amp;amp;count;&lt;BR /&gt;
 retain rate: payment:; &lt;BR /&gt;
 i+1;&lt;BR /&gt;
 r{i} = rate; p{i} =payment;&lt;BR /&gt;
 if last.company then do; &lt;BR /&gt;
                    output;&lt;BR /&gt;
                    i=0; &lt;BR /&gt;
                    call missing(of r{*} p{*}); &lt;BR /&gt;
                    end;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print ;run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 07 Jan 2011 05:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60044#M17001</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-01-07T05:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose this</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60045#M17002</link>
      <description>hello,&lt;BR /&gt;
&lt;BR /&gt;
although my solution combines parts of solutions already offered, i write it for&lt;BR /&gt;
the sake of time spent in finding it:&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=in;&lt;BR /&gt;
by ProvID company;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
      select max(nb) into :c from (select count(company) as nb from in&lt;BR /&gt;
      group by provid,company);&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data final;&lt;BR /&gt;
&lt;BR /&gt;
do i=1 to &amp;amp;c;&lt;BR /&gt;
set in (rename=(rate=i_rate payment=i_payment));&lt;BR /&gt;
by company notsorted;&lt;BR /&gt;
&lt;BR /&gt;
array rate   {&amp;amp;c} ;&lt;BR /&gt;
array payment {&amp;amp;c} ;&lt;BR /&gt;
&lt;BR /&gt;
rate{i}=i_rate;&lt;BR /&gt;
payment{i}=i_payment;&lt;BR /&gt;
&lt;BR /&gt;
if last.company then do;&lt;BR /&gt;
output;&lt;BR /&gt;
leave;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
drop i_rate i_payment i;&lt;BR /&gt;
&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Marius</description>
      <pubDate>Fri, 07 Jan 2011 10:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60045#M17002</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-07T10:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose this</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60046#M17003</link>
      <description>KSharp,&lt;BR /&gt;
&lt;BR /&gt;
I can't take credit for the idea.  It was proposed by John King and Mike Zdeb in one of the papers presented at SGF last year.  see:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/resources/papers/proceedings10/102-2010.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings10/102-2010.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Fri, 07 Jan 2011 13:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60046#M17003</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-01-07T13:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose this</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60047#M17004</link>
      <description>Thank you sooooooo much!</description>
      <pubDate>Fri, 07 Jan 2011 13:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60047#M17004</guid>
      <dc:creator>odmhx</dc:creator>
      <dc:date>2011-01-07T13:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose this</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60048#M17005</link>
      <description>Thank you soooooo much!</description>
      <pubDate>Fri, 07 Jan 2011 13:48:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60048#M17005</guid>
      <dc:creator>odmhx</dc:creator>
      <dc:date>2011-01-07T13:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose this</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60049#M17006</link>
      <description>Thank you soooooo much!!!</description>
      <pubDate>Fri, 07 Jan 2011 13:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60049#M17006</guid>
      <dc:creator>odmhx</dc:creator>
      <dc:date>2011-01-07T13:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose this</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60050#M17007</link>
      <description>Thank you sooooo much!</description>
      <pubDate>Fri, 07 Jan 2011 13:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60050#M17007</guid>
      <dc:creator>odmhx</dc:creator>
      <dc:date>2011-01-07T13:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose this</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60051#M17008</link>
      <description>Thank you ALL, so so much! I like the codes from everyone and I'll save them all to digest and use not only in this program, but also in the future!   Again, milions thanks to you all!</description>
      <pubDate>Fri, 07 Jan 2011 13:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60051#M17008</guid>
      <dc:creator>odmhx</dc:creator>
      <dc:date>2011-01-07T13:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to transpose this</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60052#M17009</link>
      <description>Hi.Art T.&lt;BR /&gt;
It looks like that it is time for me to find more in documentation.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Mon, 10 Jan 2011 01:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-transpose-this/m-p/60052#M17009</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-01-10T01:09:55Z</dc:date>
    </item>
  </channel>
</rss>

