<?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: Stack Data sets in all permutation? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609720#M177515</link>
    <description>&lt;P&gt;You may want to consider using the INDSNAME= option on the SET statement if you want to know which data set contributed which record&lt;/P&gt;</description>
    <pubDate>Thu, 05 Dec 2019 15:59:55 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-12-05T15:59:55Z</dc:date>
    <item>
      <title>Stack Data sets in all permutation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609473#M177451</link>
      <description>&lt;P&gt;Hello All,&lt;BR /&gt;I have some data sets and I need to "stack" them in all combinations possible where the data obs within each sub-set cannot change, (they have to stay in their subset order).&amp;nbsp; (I have seen a lot of info on creating a combinations/permutations of columns of a single data set, that is not what I need)&lt;BR /&gt;Here I have shown a manual way to do a full set of three items 3! (three factorial) = 6 as you all know this gets nuts quick with say 7 or 15 items. Any help would be greatly appreciated. I was hoping to do some macro and just hand it my list of sets.&amp;nbsp; Is this possible? -KJ&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data abc;&lt;BR /&gt;set a&lt;BR /&gt;b&lt;BR /&gt;c;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data acb;&lt;BR /&gt;set a&lt;BR /&gt;c&lt;BR /&gt;b;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data bac;&lt;BR /&gt;set b&lt;BR /&gt;a&lt;BR /&gt;c;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data bca;&lt;BR /&gt;set b&lt;BR /&gt;c&lt;BR /&gt;a;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data cab;&lt;BR /&gt;set c &lt;BR /&gt;a&lt;BR /&gt;b;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data cba;&lt;BR /&gt;set c&lt;BR /&gt;b&lt;BR /&gt;a;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 18:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609473#M177451</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2019-12-04T18:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Stack Data sets in all permutation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609474#M177452</link>
      <description>If you add an order variable to each data set and then use the approaches you've found so far and sort at the end by your order variables, would that work?&lt;BR /&gt;&lt;BR /&gt;What is the expected output from this? Especially since the values overlap?</description>
      <pubDate>Wed, 04 Dec 2019 18:34:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609474#M177452</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-12-04T18:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: Stack Data sets in all permutation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609493#M177460</link>
      <description>I am not sure on "order variable", I guess I need to read more on SAS permutations. &lt;BR /&gt;As for your second question, I am producing csv* files in my next step that is not an issue, *that is my last step.</description>
      <pubDate>Wed, 04 Dec 2019 19:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609493#M177460</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2019-12-04T19:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: Stack Data sets in all permutation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609495#M177461</link>
      <description>I meant, given the above data sets as an exact input, what exact output would you expect.</description>
      <pubDate>Wed, 04 Dec 2019 19:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609495#M177461</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-12-04T19:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: Stack Data sets in all permutation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609505#M177462</link>
      <description>&lt;P&gt;In my case, if my data output name is ABC, the data set should be added&lt;/P&gt;
&lt;P&gt;first A, then B, then C.&lt;BR /&gt;If the output name was CAB then the stacked data should be added in the order C, then A, then last B.&lt;BR /&gt;The names could be 1 2 3 that makes no difference to me. I eventually just need the data created into new data sets with every permutation of the sub-sets still intact.&lt;/P&gt;
&lt;P&gt;...or if this helps my sets names could be 12_, 13_,14_, 15_, and maybe one output name would be 15_12_13_14_.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*oops I do not think SAS takes a data set starting with a 'number', but A15, A14, A13, etc... would work fine. &lt;BR /&gt;&lt;BR /&gt;Does that answer your follow up? -KJ&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 19:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609505#M177462</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2019-12-04T19:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Stack Data sets in all permutation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609506#M177463</link>
      <description>&lt;P&gt;Variation on the "columns" permutation.&lt;/P&gt;
&lt;P&gt;make sure the size of the array elements is sufficient to hold any of the libname.dataset names.(41 should work for typical SAS names.&lt;/P&gt;
&lt;P&gt;Call execute is one way to build code. You could use the data _null_ set to write to a text file and include that as a program or to run later. You still have a limitation on how long this may run with large numbers of values in the X array. I just number the output sets as combinations of actual data set names as text is very likely to exceed the length of valid data set names. Or leave the I variable in the work.perm and you have a key back to the order used if needed.&lt;/P&gt;
&lt;PRE&gt;data work.perm (keep=namelist);
   array x [3] $10 ('work.A' 'work.B' 'work.C');
   n=dim(x);
   nfact=fact(n); 
   do i=1 to nfact;   
      names=allperm(i, of x[*]);
      namelist = catx(' ',of x[*]);
      output;
   end;
run;

data _null_;
   set work.perm ;
   outset = cats('work.DS_',_n_);
   call execute( 'data '||outset||'; set '|| namelist ||';run;');
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Dec 2019 19:56:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609506#M177463</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-04T19:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: Stack Data sets in all permutation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609513#M177465</link>
      <description>&lt;P&gt;Do datasets a, b and c have the same number of observations? Are you going to be concatenating all these datasets at some point?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 20:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609513#M177465</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-12-04T20:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: Stack Data sets in all permutation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609554#M177481</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43996"&gt;@kjohnsonm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have some data sets and I need to "stack" them in all combinations possible (...)&lt;BR /&gt;As for your second question, I am producing csv* files in my next step that is not an issue, *that is my last step.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To me this sounds a bit like an "&lt;A href="http://xyproblem.info/" target="_blank" rel="noopener"&gt;XY problem&lt;/A&gt;." Wouldn't it be possible to create those csv files from a single dataset containing the subsets in one order, e.g., dataset &lt;FONT face="courier new,courier"&gt;abc&lt;/FONT&gt;&amp;nbsp;in your example? After all, no new information would be created by generating all subset permutations. You can read a dataset in any order and multiple times (if need be) and create multiple csv files from that dataset in a single DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit (addendum):&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data for demonstration */

data have(keep=make seqno);
set sashelp.cars(where=(make in ('Acura','Buick','Cadillac')));
by make;
if first.make then seqno=1;
else seqno+1;
run; /* 7+9+8=24 obs. */

%let s=3; /* number of subgroups */
%let dir=C:\Temp\;

/* Create 3!=6 CSV files C:\Temp\123.csv, 132.csv, ..., 321.csv
   containing the correspondingly permuted 3 subgroups of HAVE */

data _null_;
array x[&amp;amp;s] (1:&amp;amp;s);
array p[&amp;amp;s] _temporary_; /* starting positions */
length fname $50;
do until(last);
  set have end=last;
  by make notsorted;
  if first.make then do;
    j+1;
    p[j]=_n_;
  end;
  _n_+1;
end;
do i=1 to fact(dim(x));
  call allperm(i, of x[*]);
  fname=cats("&amp;amp;dir", of x[*], ".csv");
  file dummy filevar=fname dsd;
  put 'Make,Seqno';
  do j=1 to dim(x);
    do k=p[x[j]] to mod(n+p[mod(x[j],&amp;amp;s)+1]-2,n)+1;
      set have point=k nobs=n;
      put make seqno;
    end;
  end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 16:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609554#M177481</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-12-05T16:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Stack Data sets in all permutation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609556#M177483</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43996"&gt;@kjohnsonm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;In my case, if my data output name is ABC, the data set should be added&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*oops I do not think SAS takes a data set starting with a 'number', but A15, A14, A13, etc... would work fine. &lt;BR /&gt;&lt;BR /&gt;Does that answer your follow up? -KJ&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which is why my example code uses DS_ as the base of the name with a counter variable to add a numeric suffix.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 22:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609556#M177483</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-04T22:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Stack Data sets in all permutation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609705#M177510</link>
      <description>&lt;P&gt;&lt;A class="lia-link-navigation lia-page-link lia-user-name-link" id="link_45" style="background-attachment: scroll; background-clip: border-box; background-color: transparent; background-image: none; background-origin: padding-box; background-position-x: 0%; background-position-y: 0%; background-repeat: repeat; background-size: auto; box-sizing: inherit; color: #009999; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884" target="_self"&gt;&lt;SPAN class="login-bold" style="box-sizing: inherit; font-weight: bold;"&gt;ballardw&lt;/SPAN&gt;&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;You are a true SAS supper user.&amp;nbsp; Thank you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.perm (keep=namelist);
array x [3] $10 ('A' 'B' 'C');
n=dim(x);
nfact=fact(n); 
do i=1 to nfact; 
names=allperm(i, of x[*]);
namelist = catx(' ',of x[*]);
output;
end;
run; proc print data=perm noobs;run;
data temp;
set work.perm ;
/* outset = cats('work.DS_',_n_);*/ /* This code will make output data sets like DS_# where the number will be 1-6 for a three set list.  or n!  --needed for if your data sets have longer names than when joined SAS will allow. */
outset =compress(namelist,,'s');  /* This fits my simple example data model  */
my_call="call execute( 'data '||outset||'; set '|| namelist ||';run;')";
call execute( 'data '||outset||'; set '|| namelist ||';run;');
run;
proc print data=temp;run;
proc print data=ACB ;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 15:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609705#M177510</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2019-12-05T15:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Stack Data sets in all permutation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609706#M177511</link>
      <description>...in my case no they did not. They could have any number of lines greater than 30 or so.</description>
      <pubDate>Thu, 05 Dec 2019 15:29:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609706#M177511</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2019-12-05T15:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Stack Data sets in all permutation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609716#M177513</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*PS if you modify your code to */
data temp;
   set work.perm ;
   outset = cats('work.DS_',_n_);
/*   outset =compress(namelist,,'s');*/
   n = _n_;
   call execute( 'data '||outset||'; set '|| namelist ||';run;');
   keep outset n namelist ;
run;
proc print data=temp noobs;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will get output like this:&lt;/P&gt;
&lt;P&gt;namelist outset n&lt;/P&gt;
&lt;P&gt;A B C work.DS_1 1&lt;BR /&gt;A C B work.DS_2 2&lt;BR /&gt;C A B work.DS_3 3&lt;BR /&gt;C B A work.DS_4 4&lt;BR /&gt;B C A work.DS_5 5&lt;BR /&gt;B A C work.DS_6 6&lt;BR /&gt;That can be used as a simple x-cross walk to your data set names from your source names if your N is large or your data set names are too large. Thanks again cheers -KJ&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 15:40:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609716#M177513</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2019-12-05T15:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Stack Data sets in all permutation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609720#M177515</link>
      <description>&lt;P&gt;You may want to consider using the INDSNAME= option on the SET statement if you want to know which data set contributed which record&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 15:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-Data-sets-in-all-permutation/m-p/609720#M177515</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-05T15:59:55Z</dc:date>
    </item>
  </channel>
</rss>

