<?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 Concatenate permutations of columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665095#M198793</link>
    <description>&lt;P&gt;Starting data&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ quarter $ col1 $ col2 $ col3 $ col4 $;
datalines;
LF first scooter car bus foot
LF second bike bus car .
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;I want to concatenate all permutations of each id/quarter columns. For example, the final result should be:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length id $4 quarter $10 col1 $10 col2 $10 col3 $10 col4 $10 want1 $25 want2 $25 want3 $25 want4 $25 want5 $25 want6 $25 want7 $25 want8 $25 want9 $25 want10 $25 want11 $25;
input id $ quarter $ col1 $ col2 $ col3 $ col4 $ want1 $ want2 $ want3 $ want4 want5 $ want6 $ want7 $ want8 $ want9 $ want10 $ want11 $;
datalines;
LF first scooter car bus foot scooter/car scooter/bus scooter/foot scooter/car/bus scooter/car/foot scooter/bus/foot scooter/car/bus/foot car/bus car/foot car/bus/foot bus/foot
LF second bike bus car . bike/bus bike/car bike/bus/car bus/car . . . . . . .
; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have enough grasp of SAS to be able to capture some permutations such as concatenating col1+col2; col1+col3... col2+col3...and finally col1-col4. But my grasp isn't enough to be able to capture all possible permutations (such as col1+col2+col4).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated!&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jun 2020 17:46:01 GMT</pubDate>
    <dc:creator>LFern</dc:creator>
    <dc:date>2020-06-25T17:46:01Z</dc:date>
    <item>
      <title>Concatenate permutations of columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665095#M198793</link>
      <description>&lt;P&gt;Starting data&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ quarter $ col1 $ col2 $ col3 $ col4 $;
datalines;
LF first scooter car bus foot
LF second bike bus car .
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;I want to concatenate all permutations of each id/quarter columns. For example, the final result should be:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length id $4 quarter $10 col1 $10 col2 $10 col3 $10 col4 $10 want1 $25 want2 $25 want3 $25 want4 $25 want5 $25 want6 $25 want7 $25 want8 $25 want9 $25 want10 $25 want11 $25;
input id $ quarter $ col1 $ col2 $ col3 $ col4 $ want1 $ want2 $ want3 $ want4 want5 $ want6 $ want7 $ want8 $ want9 $ want10 $ want11 $;
datalines;
LF first scooter car bus foot scooter/car scooter/bus scooter/foot scooter/car/bus scooter/car/foot scooter/bus/foot scooter/car/bus/foot car/bus car/foot car/bus/foot bus/foot
LF second bike bus car . bike/bus bike/car bike/bus/car bus/car . . . . . . .
; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have enough grasp of SAS to be able to capture some permutations such as concatenating col1+col2; col1+col3... col2+col3...and finally col1-col4. But my grasp isn't enough to be able to capture all possible permutations (such as col1+col2+col4).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 17:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665095#M198793</guid>
      <dc:creator>LFern</dc:creator>
      <dc:date>2020-06-25T17:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate permutations of columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665104#M198796</link>
      <description>&lt;P&gt;Is this a programming exercise or is the output actually going to be used for something? If it is to be used it might be a good idea to describe what the intended use actually would be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For entertainment you can look and the documentation for ALLPERM and CALL ALLPERM functions. And you may want to be careful of wanting Permutation or Combinations (ALLCOMB, CALL ALLCOMB and CALL ALLCOMBI). Permutations consider order as well, so if you have A and B you get A,B and B,A as results.&lt;/P&gt;
&lt;P&gt;Or the the Lexcomb versions because you apparently will have missing values for some.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 17:57:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665104#M198796</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-25T17:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate permutations of columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665109#M198800</link>
      <description>&lt;P&gt;It's not an exercise. Once I know all the possible combinations of transportation a person could have in a quarter, I'll need to transform it into long-format and merge on another dataset. I'll definitely look into some of the functions you mentioned. Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 18:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665109#M198800</guid>
      <dc:creator>LFern</dc:creator>
      <dc:date>2020-06-25T18:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate permutations of columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665110#M198801</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262848"&gt;@LFern&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It's not an exercise. Once I know all the possible combinations of transportation a person could have in a quarter, I'll need to transform it into long-format and merge on another dataset. I'll definitely look into some of the functions you mentioned. Thank you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;At least in my mind, what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;was talking about was what ANALYSIS will you be doing when you complete this creation of permutations. Saying you're going to merge the permutations with another data set really isn't what we were looking for. The reason I make this point is because the ANALYSIS you will be doing may (or may not) be easier with the data arranged in some other fashion.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 18:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665110#M198801</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-06-25T18:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate permutations of columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665148#M198825</link>
      <description>&lt;P&gt;You want combinations, not permutations. Here is how to get them, while eliminating those with missing values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ quarter $ a $ b $ c $ d $;
datalines;
LF first scooter car bus foot
LF second bike bus car .
;

data want;
set have;
array _a a--d;
do i = 1 to dim(_a);
    do j = 1 to comb(dim(_a), i);
        call allcomb(j, i, of _a{*});
        length comb $64;
        call missing (comb);
        do k = 1 to i;
            if missing(_a{k}) then leave;
            comb = catx("/", comb, _a{k});
            end;
        if k &amp;gt; i then output;
        end;
    end;
keep id quarter comb;
run;

proc print data=want noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;id 	quarter 	comb
LF 	first 	scooter
LF 	first 	foot
LF 	first 	bus
LF 	first 	car
LF 	first 	car/bus
LF 	first 	car/scooter
LF 	first 	car/foot
LF 	first 	bus/foot
LF 	first 	bus/scooter
LF 	first 	foot/scooter
LF 	first 	foot/scooter/bus
LF 	first 	foot/scooter/car
LF 	first 	foot/bus/car
LF 	first 	scooter/bus/car
LF 	first 	scooter/bus/car/foot
LF 	second 	bike
LF 	second 	car
LF 	second 	bus
LF 	second 	bus/car
LF 	second 	bus/bike
LF 	second 	car/bike
LF 	second 	bike/car/bus&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jun 2020 20:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665148#M198825</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-06-25T20:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate permutations of columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665153#M198829</link>
      <description>&lt;P&gt;Hello, thank you so much!&amp;nbsp;This perfectly executes what I wanted. However, I'm new to arrays and would like to understand your code more. Why did you select "99" here? I changed it to a couple of other numbers but didn't notice a change in the final output.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array _b{99} $8 _temporary_;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you again.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 20:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665153#M198829</guid>
      <dc:creator>LFern</dc:creator>
      <dc:date>2020-06-25T20:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate permutations of columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665157#M198831</link>
      <description>&lt;P&gt;I took out that statement. It defined a temporary array that wasn't needed in the end. You would use it if you wanted to sort the list elements before concatenating them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About the statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array _b{99} $8 _temporary_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The value 99 is meant to be greater than dim(_a), because array _b was intended to hold a copy of array _a. Ideally I would like to write&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array _b{dim(_a)} $8 _temporary_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but unfortunately SAS only allows constant numbers and "*" as array dimensions.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 21:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-permutations-of-columns/m-p/665157#M198831</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-06-25T21:47:40Z</dc:date>
    </item>
  </channel>
</rss>

