<?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: Capturing values of a variable while collapsing by another variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/339721#M77533</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input transaction step action $;
cards4;
1 1 buy
1 2 sell
1 3 buy
2 1 buy
2 2 loan
2 3 sell
;;;;
run;quit;

proc sort data=have out=havunq nodupkey;
by transaction action;
run;quit;

data want;
 length rol $200;
 retain rol ' ';
 set havunq;
 by transaction;
 rol=catx('/',rol,action);
 if last.transaction then do;
   output;
   rol=' ';
 end;
 keep transaction rol;
run;quit;



transaction   actions
1              buy/sell
2              buy/loan/sell

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 09 Mar 2017 17:56:22 GMT</pubDate>
    <dc:creator>rogerjdeangelis</dc:creator>
    <dc:date>2017-03-09T17:56:22Z</dc:date>
    <item>
      <title>Capturing values of a variable while collapsing by another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/339718#M77530</link>
      <description>&lt;P&gt;Say we have a data like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;transaction &amp;nbsp; &amp;nbsp; &amp;nbsp;step &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; action&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;buy&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sell&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;buy&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; buy&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; loan&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sell&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to collapse the data &amp;nbsp;into something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;transaction &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; action_sequence&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;buy/sell/buy&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;buy/loan/sell&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and waht if i only want to keep the unique values, like this&lt;/P&gt;&lt;P&gt;transaction &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; actions&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; buy/sell&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; buy/loan/sell&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can this be done with proc sql? Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 17:41:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/339718#M77530</guid>
      <dc:creator>apolitical</dc:creator>
      <dc:date>2017-03-09T17:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing values of a variable while collapsing by another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/339721#M77533</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input transaction step action $;
cards4;
1 1 buy
1 2 sell
1 3 buy
2 1 buy
2 2 loan
2 3 sell
;;;;
run;quit;

proc sort data=have out=havunq nodupkey;
by transaction action;
run;quit;

data want;
 length rol $200;
 retain rol ' ';
 set havunq;
 by transaction;
 rol=catx('/',rol,action);
 if last.transaction then do;
   output;
   rol=' ';
 end;
 keep transaction rol;
run;quit;



transaction   actions
1              buy/sell
2              buy/loan/sell

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Mar 2017 17:56:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/339721#M77533</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-09T17:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing values of a variable while collapsing by another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/339724#M77534</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/69320"&gt;@apolitical&lt;/a&gt; wrote:&lt;BR /&gt;&amp;nbsp;
&lt;P&gt;&lt;BR /&gt;Can this be done with proc sql? Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is not easy in PROC SQL, at least the SAS flavour. You essentially would transpose it and then collapse the values or use a recursive join of some type but know how many are required would make it a little more difficult. Oracle SQL or T-SQL have WINDOW or PARTITION syntax that make it easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A data step to collapse rows is much more efficient and much easier to code.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 17:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/339724#M77534</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-09T17:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing values of a variable while collapsing by another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/339777#M77552</link>
      <description>thank you. that works!</description>
      <pubDate>Thu, 09 Mar 2017 20:33:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/339777#M77552</guid>
      <dc:creator>apolitical</dc:creator>
      <dc:date>2017-03-09T20:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing values of a variable while collapsing by another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/340015#M77658</link>
      <description>Oh and also, what if I want to record all actions in their sequence and not eliminate duplicates? for something like this:&lt;BR /&gt;&lt;BR /&gt;transaction action_sequence&lt;BR /&gt;1 buy/sell/buy&lt;BR /&gt;2 buy/loan/sell</description>
      <pubDate>Fri, 10 Mar 2017 15:20:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/340015#M77658</guid>
      <dc:creator>apolitical</dc:creator>
      <dc:date>2017-03-10T15:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing values of a variable while collapsing by another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/340127#M77701</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/69320"&gt;@apolitical&lt;/a&gt; wrote:&lt;BR /&gt;Oh and also, what if I want to record all actions in their sequence and not eliminate duplicates? for something like this:&lt;BR /&gt;&lt;BR /&gt;transaction action_sequence&lt;BR /&gt;1 buy/sell/buy&lt;BR /&gt;2 buy/loan/sell&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/42345"&gt;@rogerjdeangelis&lt;/a&gt;&amp;nbsp;solution but remove the NODUPKEY from the SORT should do it.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2017 23:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/340127#M77701</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-10T23:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing values of a variable while collapsing by another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/342163#M78425</link>
      <description>&lt;P&gt;thanks. that in hindsight should have been obvious..&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2017 21:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-values-of-a-variable-while-collapsing-by-another/m-p/342163#M78425</guid>
      <dc:creator>apolitical</dc:creator>
      <dc:date>2017-03-17T21:19:04Z</dc:date>
    </item>
  </channel>
</rss>

