<?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: Data Transpose with proc summary and column reaarangement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251937#M47696</link>
    <description>&lt;P&gt;Check CALL EXECUTE().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf" target="_blank" rel="nofollow"&gt;http://support.sas.com/resources/papers/proceeding&lt;WBR /&gt;s15/2785-2015.pdf&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Feb 2016 01:40:06 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-02-24T01:40:06Z</dc:date>
    <item>
      <title>Data Transpose with proc summary and column reaarangement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251353#M47470</link>
      <description>&lt;P&gt;Hi, I'm transposing the data with Proc summary and the code is as below -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input PT DT RULE_ID RULE_CAT;&lt;BR /&gt;cards;&lt;BR /&gt;1 10 20 20&lt;BR /&gt;1 10 21 20&lt;BR /&gt;1 10 22 20&lt;BR /&gt;1 10 23 20&lt;BR /&gt;1 11 20 20&lt;BR /&gt;1 11 21 20&lt;BR /&gt;1 11 22 20&lt;BR /&gt;1 11 23 20&lt;BR /&gt;1 12 20 20&lt;BR /&gt;1 12 21 20&lt;BR /&gt;1 12 22 20&lt;BR /&gt;1 12 23 20&lt;BR /&gt;2 10 20 20&lt;BR /&gt;2 10 21 20&lt;BR /&gt;2 10 22 20&lt;BR /&gt;2 10 23 20&lt;BR /&gt;2 11 20 20&lt;BR /&gt;2 11 21 20&lt;BR /&gt;2 11 22 20&lt;BR /&gt;2 11 23 20&lt;BR /&gt;2 12 20 20&lt;BR /&gt;2 12 21 20&lt;BR /&gt;2 12 22 20&lt;BR /&gt;2 12 23 20&lt;BR /&gt;;;;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql noprint feedback;&lt;BR /&gt;select max(ptcount) into :dim &lt;BR /&gt;from (select count(PT) as ptcount from have group by PT, DT);&lt;BR /&gt;quit;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;OPTIONS SYMBOLGEN;&lt;BR /&gt;proc summary data=have nway;&lt;BR /&gt;class PT DT;&lt;BR /&gt;output out=need idgroup(out[&amp;amp;dim](RULE_ID: RULE_CAT: )=);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With the above code my final dataset &lt;I&gt;need&lt;/I&gt;&amp;nbsp;looks like below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/1982iC7373A8B842ED6D2/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture1.1.JPG" title="Capture1.1.JPG" /&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/1983iF9F2955EA9809A30/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture1.2.JPG" title="Capture1.2.JPG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the question now is - columns need to be rearranged like, RULE_ID_1, RULE_CAT_1,&amp;nbsp;&lt;SPAN&gt;RULE_ID_2, RULE_CAT_2,&lt;/SPAN&gt;&lt;SPAN&gt;RULE_ID_3, RULE_CAT_3,&lt;/SPAN&gt;&lt;SPAN&gt;RULE_ID_4, RULE_CAT_4.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Is this possible? Because the number of columns getting created is random and based on the value of the macro variable &lt;EM&gt;dim&lt;/EM&gt; getting created from Proc Sql.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please share your views and suggestions.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Feb 2016 19:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251353#M47470</guid>
      <dc:creator>Balas</dc:creator>
      <dc:date>2016-02-20T19:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transpose with proc summary and column reaarangement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251361#M47471</link>
      <description>&lt;P&gt;Do it with a datastep. No macro variable needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have; by pt dt; run;

data long;
set have; by pt dt;
if first.dt then i = 0;
i + 1;
var = cats("RULE_ID_", i);
value = rule_id;
output;
var = cats("RULE_CAT_", i);
value = rule_cat;
output;
keep pt dt var value;
run;

proc transpose data=long out=want(drop=_name_);
by pt dt;
var value;
id var;
run;

proc print data=want noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Feb 2016 23:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251361#M47471</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-02-20T23:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transpose with proc summary and column reaarangement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251394#M47494</link>
      <description>&lt;P&gt;Thanks PG Stats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your solution works absolutely well with the small datasets like the one provided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But creating the &lt;EM&gt;long&lt;/EM&gt; dataset with multi millions of records will take huge CPU time and memory where a column holds all the variable names needs to be transposed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please suggest - If I need to apply the same logic on huge datasets, do I need to tweak the logic or do we have any new logic to be built?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Feb 2016 09:43:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251394#M47494</guid>
      <dc:creator>Balas</dc:creator>
      <dc:date>2016-02-21T09:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transpose with proc summary and column reaarangement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251456#M47518</link>
      <description>&lt;P&gt;Now it is MERGE time. Check MERGE skill me,Matt, Arthur.T proposed, if your table is big ,check CALL EXECUTE().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf&lt;/A&gt;&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 PT DT RULE_ID RULE_CAT;
cards;
1 10 20 20
1 10 21 20
1 10 22 20
1 10 23 20
1 11 20 20
1 11 21 20
1 11 22 20
1 11 23 20
1 12 20 20
1 12 21 20
1 12 22 20
1 12 23 20
2 10 20 20
2 10 21 20
2 10 22 20
2 10 23 20
2 11 20 20
2 11 21 20
2 11 22 20
2 11 23 20
2 12 20 20
2 12 21 20
2 12 22 20
2 12 23 20
;;;;
run;
data have;
 set have;
 by PT DT;
 if first.DT then n=0;
 n+1;
run;
proc sql;
select distinct catt('have(where=(n=',n,') 
                     rename=(RULE_ID=RULE_ID_',n,' RULE_CAT=RULE_CAT_',n,'))')
        into : list separated by ' '
 from have;
quit;
data want;
 merge &amp;amp;list ;
 by PT DT;
 drop n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make it better.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 03:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251456#M47518</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-02-23T03:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transpose with proc summary and column reaarangement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251462#M47521</link>
      <description>&lt;P&gt;For a huge dataset, it is indeed preferable to use another strategy. Here is what I would try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
retain count;
length varlist $2000;
do i = 1 by 1 until(last.dt);
    set have end=done; by pt dt notsorted;
    end;
count = max(count, i);
if done then do;
    do i = 1 to count;
        varList = catx(" ", varList, cats("RULE_ID_", i), cats("RULE_CAT_", i));
        end;
    call symputx("varList", varlist);
    end;
run;

%put &amp;amp;varList;

data want;
do i = 1 by 2 until(last.dt);
    set have end=done; by pt dt notsorted;
    array v &amp;amp;varList;
    v{i} = RULE_ID; v{i+1} = RULE_CAT;
    end;
drop i RULE_ID RULE_CAT;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Feb 2016 03:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251462#M47521</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-02-22T03:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transpose with proc summary and column reaarangement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251585#M47571</link>
      <description>&lt;P&gt;Perfect. Thanks PG Stats.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 18:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251585#M47571</guid>
      <dc:creator>Balas</dc:creator>
      <dc:date>2016-02-22T18:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transpose with proc summary and column reaarangement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251586#M47572</link>
      <description>&lt;P&gt;Thanks Ksharp. Solution Worked perfectly well with the small&amp;nbsp;datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I faced a problem, while creating a macro variable &lt;STRONG&gt;&lt;EM&gt;list&lt;/EM&gt;&lt;/STRONG&gt;, the maximum allowable character length is more or less 6000 only.&lt;/P&gt;
&lt;P&gt;If the length is more the value (for &lt;STRONG&gt;&lt;EM&gt;List&lt;/EM&gt;&lt;/STRONG&gt;) is getting truncated for huge datasets and the code execution is getting stopped with the Error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please suggest how to rectify this unwanted truncation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 17:25:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251586#M47572</guid>
      <dc:creator>Balas</dc:creator>
      <dc:date>2016-02-23T17:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transpose with proc summary and column reaarangement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251687#M47598</link>
      <description>&lt;P&gt;PG,&lt;/P&gt;
&lt;P&gt;1) What if one of them is CHARACTER variable?&lt;/P&gt;
&lt;P&gt;2) Once you get variable list &amp;amp;listVar, why not use RETAIN statment on the OP's original data ?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 01:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251687#M47598</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-02-23T01:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transpose with proc summary and column reaarangement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251707#M47605</link>
      <description>&lt;P&gt;The code is meant to be fast for the problem at hand. It reads the data only twice and it doesn't create any intermediate dataset. Writing the first step in SQL might be a better strategy if it could be run on a server.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 03:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251707#M47605</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-02-23T03:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transpose with proc summary and column reaarangement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251937#M47696</link>
      <description>&lt;P&gt;Check CALL EXECUTE().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf" target="_blank" rel="nofollow"&gt;http://support.sas.com/resources/papers/proceeding&lt;WBR /&gt;s15/2785-2015.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 01:40:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transpose-with-proc-summary-and-column-reaarangement/m-p/251937#M47696</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-02-24T01:40:06Z</dc:date>
    </item>
  </channel>
</rss>

