<?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 Proc Transpose /  Cross Tab question in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Cross-Tab-question/m-p/44920#M11836</link>
    <description>Hi.  Can you please help me with the following issue...  &lt;BR /&gt;
&lt;BR /&gt;
The Data looks like this:&lt;BR /&gt;
cust_id     acct     hierarchy     amt&lt;BR /&gt;
1     123     aa     $100&lt;BR /&gt;
1     125     bb     $250&lt;BR /&gt;
1     121     cc     $125&lt;BR /&gt;
2     234     aa     $100&lt;BR /&gt;
2     254     aa     $300&lt;BR /&gt;
3     333     aa     $200&lt;BR /&gt;
3     345     bb     $250&lt;BR /&gt;
3     365     bb     $210&lt;BR /&gt;
3     344     cc     $75&lt;BR /&gt;
&lt;BR /&gt;
and it needs to look like this:&lt;BR /&gt;
cust_id..acct....aa....bb.....cc.....total&lt;BR /&gt;
1...........123....$100.................$100&lt;BR /&gt;
1...........125...........$250..........$250&lt;BR /&gt;
1...........121..................$125...$125&lt;BR /&gt;
2...........234....$100.................$100&lt;BR /&gt;
2...........254....$300.................$300&lt;BR /&gt;
3...........333....$200.................$200&lt;BR /&gt;
3...........345....$250.................$250&lt;BR /&gt;
3...........365............$210.........$210&lt;BR /&gt;
3...........344...................$75...$75&lt;BR /&gt;
Some points about the data - &lt;BR /&gt;
1. each acct will only have one amt, so the [total] value in the new dataset equals the amt and will not be a summation.&lt;BR /&gt;
2. there will be over 50 different hierarchy values and they cannot be hard coded.&lt;BR /&gt;
&lt;BR /&gt;
Thank you for your help.</description>
    <pubDate>Mon, 15 Jun 2009 22:14:25 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-06-15T22:14:25Z</dc:date>
    <item>
      <title>Proc Transpose /  Cross Tab question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Cross-Tab-question/m-p/44920#M11836</link>
      <description>Hi.  Can you please help me with the following issue...  &lt;BR /&gt;
&lt;BR /&gt;
The Data looks like this:&lt;BR /&gt;
cust_id     acct     hierarchy     amt&lt;BR /&gt;
1     123     aa     $100&lt;BR /&gt;
1     125     bb     $250&lt;BR /&gt;
1     121     cc     $125&lt;BR /&gt;
2     234     aa     $100&lt;BR /&gt;
2     254     aa     $300&lt;BR /&gt;
3     333     aa     $200&lt;BR /&gt;
3     345     bb     $250&lt;BR /&gt;
3     365     bb     $210&lt;BR /&gt;
3     344     cc     $75&lt;BR /&gt;
&lt;BR /&gt;
and it needs to look like this:&lt;BR /&gt;
cust_id..acct....aa....bb.....cc.....total&lt;BR /&gt;
1...........123....$100.................$100&lt;BR /&gt;
1...........125...........$250..........$250&lt;BR /&gt;
1...........121..................$125...$125&lt;BR /&gt;
2...........234....$100.................$100&lt;BR /&gt;
2...........254....$300.................$300&lt;BR /&gt;
3...........333....$200.................$200&lt;BR /&gt;
3...........345....$250.................$250&lt;BR /&gt;
3...........365............$210.........$210&lt;BR /&gt;
3...........344...................$75...$75&lt;BR /&gt;
Some points about the data - &lt;BR /&gt;
1. each acct will only have one amt, so the [total] value in the new dataset equals the amt and will not be a summation.&lt;BR /&gt;
2. there will be over 50 different hierarchy values and they cannot be hard coded.&lt;BR /&gt;
&lt;BR /&gt;
Thank you for your help.</description>
      <pubDate>Mon, 15 Jun 2009 22:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Cross-Tab-question/m-p/44920#M11836</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-15T22:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Transpose /  Cross Tab question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Cross-Tab-question/m-p/44921#M11837</link>
      <description>This is simple with data step logic. See the below code. Does it solve your problem ?&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
select distinct(hierarchy) into: var separated by ' ' from test;&lt;BR /&gt;
select count(distinct hierarchy) into : N from test;&lt;BR /&gt;
quit; &lt;BR /&gt;
&lt;BR /&gt;
proc sort data=test;&lt;BR /&gt;
   by cust_id hierarchy;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%macro dummy;&lt;BR /&gt;
data test2(rename=(amt=total) drop=hierarchy);&lt;BR /&gt;
  set test;&lt;BR /&gt;
  %do i=1 %to &amp;amp;N;&lt;BR /&gt;
    %let var1=%scan("&amp;amp;var", &amp;amp;i, " ");&lt;BR /&gt;
    if hierarchy="&amp;amp;var1" then &amp;amp;var1=amt;&lt;BR /&gt;
  %end;&lt;BR /&gt;
run;&lt;BR /&gt;
%mend dummy;&lt;BR /&gt;
&lt;BR /&gt;
%dummy;&lt;BR /&gt;
&lt;BR /&gt;
~ Sukanya E

Message was edited by: Sukanya</description>
      <pubDate>Mon, 15 Jun 2009 23:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Cross-Tab-question/m-p/44921#M11837</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-15T23:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Transpose /  Cross Tab question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Cross-Tab-question/m-p/44922#M11838</link>
      <description>Hi:&lt;BR /&gt;
  If the data is as you describe, then either PROC TABULATE or PROC REPORT would be another way to do this. I'd probably use PROC REPORT because of the requirement to repeat the CUST_ID on every report row.&lt;BR /&gt;
  &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
data cust;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input cust_id acct hierarchy $ amt : comma4.;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 123 aa $100&lt;BR /&gt;
1 125 bb $250&lt;BR /&gt;
1 121 cc $125&lt;BR /&gt;
2 234 aa $100&lt;BR /&gt;
2 254 aa $300&lt;BR /&gt;
3 333 aa $200&lt;BR /&gt;
3 345 bb $250&lt;BR /&gt;
3 365 bb $210&lt;BR /&gt;
3 344 cc $75&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
                  &lt;BR /&gt;
ods listing close;&lt;BR /&gt;
ods html file='c:\temp\crosstab.html' style=sasweb;&lt;BR /&gt;
  proc tabulate data=cust f=dollar6.;&lt;BR /&gt;
  title 'Proc Tabulate';&lt;BR /&gt;
  class cust_id acct hierarchy /order=data;&lt;BR /&gt;
  var amt;&lt;BR /&gt;
  table cust_id * acct,&lt;BR /&gt;
        hierarchy*amt=' ' all*amt=' ';&lt;BR /&gt;
  keylabel sum=' ';&lt;BR /&gt;
  run;&lt;BR /&gt;
                  &lt;BR /&gt;
  proc report data=cust nowd;&lt;BR /&gt;
    title 'Proc Report';&lt;BR /&gt;
    column cust_id show_cust acct amt,hierarchy amt=alltot;&lt;BR /&gt;
    define cust_id  / order order=data noprint;&lt;BR /&gt;
    define show_cust / computed 'Cust/ID';&lt;BR /&gt;
    define acct / order  order=data;&lt;BR /&gt;
    define amt / sum 'Hierarchy' f=dollar6.;&lt;BR /&gt;
    define hierarchy / across ' ' ;&lt;BR /&gt;
    define alltot / sum f=dollar6.;&lt;BR /&gt;
    compute before cust_id;&lt;BR /&gt;
      hold = cust_id;&lt;BR /&gt;
    endcomp;&lt;BR /&gt;
    compute show_cust ;&lt;BR /&gt;
       show_cust=hold;&lt;BR /&gt;
    endcomp;&lt;BR /&gt;
  run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 16 Jun 2009 02:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Cross-Tab-question/m-p/44922#M11838</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-06-16T02:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Transpose /  Cross Tab question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Cross-Tab-question/m-p/44923#M11839</link>
      <description>Thank you very much!  This is exactly what I needed.</description>
      <pubDate>Tue, 16 Jun 2009 19:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Cross-Tab-question/m-p/44923#M11839</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-16T19:44:05Z</dc:date>
    </item>
  </channel>
</rss>

