<?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 Distinct powers of integer combinations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/400882#M97179</link>
    <description>&lt;P&gt;Hello Folks, I thought it was about time i used SAS for some complex maths problems, as most of the time my main use for SAS is data manipulation. lately i've had some really nice problems to solve and in particular, help me grasp complex maths. but this particular exercise has me stumped, and i believe its due to the limitation of how i use SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;2&lt;SPAN&gt;=4, 2&lt;/SPAN&gt;3&lt;SPAN&gt;=8, 2&lt;/SPAN&gt;4&lt;SPAN&gt;=16, 2&lt;/SPAN&gt;5&lt;SPAN&gt;=32&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3&lt;/SPAN&gt;2&lt;SPAN&gt;=9, 3&lt;/SPAN&gt;3&lt;SPAN&gt;=27, 3&lt;/SPAN&gt;4&lt;SPAN&gt;=81, 3&lt;/SPAN&gt;5&lt;SPAN&gt;=243&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4&lt;/SPAN&gt;2&lt;SPAN&gt;=16, 4&lt;/SPAN&gt;3&lt;SPAN&gt;=64, 4&lt;/SPAN&gt;4&lt;SPAN&gt;=256, 4&lt;/SPAN&gt;5&lt;SPAN&gt;=1024&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;2&lt;SPAN&gt;=25, 5&lt;/SPAN&gt;3&lt;SPAN&gt;=125, 5&lt;/SPAN&gt;4&lt;SPAN&gt;=625, 5&lt;/SPAN&gt;5&lt;SPAN&gt;=3125&lt;/SPAN&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms: 4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125 How many distinct terms are in the sequence generated by ab for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is some sample code of how we are trying to solve the problem, the issue is, its taking 24hrs to run:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the issue could be that i'm not using multithreading as per datastep, so i considered casting the interger to an SQL box as we know SAS struggles with numbers beyond 15-16 characters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from some early calculations the dataset will end up with around 9800 rows, so i'm not sure where the bottleneck is&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro add_num (num1=,num2=);

%global ans;

%let len1 = %length(&amp;amp;num1);
%let len2 = %length(&amp;amp;num2);

%let maxlen = %sysfunc(max(&amp;amp;len1,&amp;amp;len2));

%if &amp;amp;maxlen ^= &amp;amp;len1 %then
  %let num1 = %sysfunc(repeat(0,%eval(&amp;amp;maxlen - &amp;amp;len1 - 1)))&amp;amp;num1;
%if &amp;amp;maxlen ^= &amp;amp;len2 %then
  %let num2 = %sysfunc(repeat(0,%eval(&amp;amp;maxlen - &amp;amp;len2 - 1)))&amp;amp;num2;

%let ten = 0;
%let ans = ;

%do i = &amp;amp;maxlen %to 1 %by -1;

  %let digit1 = %sysfunc(substr(&amp;amp;num1,&amp;amp;i,1));
  %let digit2 = %sysfunc(substr(&amp;amp;num2,&amp;amp;i,1));

  %let tmp = %eval(&amp;amp;digit1 + &amp;amp;digit2 + &amp;amp;ten);

  %if %length(&amp;amp;tmp) = 2 %then
  %do;
    %let unit = %sysfunc(substr(&amp;amp;tmp,2,1));
     %let ten = 1;
  %end;
  %else
  %do;
    %let unit = &amp;amp;tmp;
     %let ten = 0;    
  %end;

  %let ans = &amp;amp;unit&amp;amp;ans;

%end;

%if &amp;amp;ten = 1 %then 
  %let ans = &amp;amp;ten&amp;amp;ans;

/*%put Addition Complete : &amp;amp;num1 + &amp;amp;num2 = &amp;amp;ans;*/

%mend;

%macro multi_num(num1=,multi=);
%global ans;
%let num2 = &amp;amp;num1;
%let later = &amp;amp;num1;
%do j = 1 %to %eval(&amp;amp;multi - 1);
  %add_num(num1=&amp;amp;num1,num2=&amp;amp;num2);
  %let num1 = &amp;amp;ans;
%end;
/*%put Multiplication Complete : &amp;amp;num2 x &amp;amp;multi = &amp;amp;ans;*/
%mend;


%macro fact(factorial=);
%global ans;
%let ans = ;
%multi_num (num1=&amp;amp;factorial,multi=%eval(&amp;amp;factorial-1));
%do a=%eval(&amp;amp;factorial-2) %to 2 %by -1;
%multi_num (num1=&amp;amp;ans,multi=&amp;amp;a);
%end;

%put Factorial Complete : &amp;amp;factorial.! is &amp;amp;ans;
%mend;

%macro expo(base=,expo=);
%global ans;
%let ans = ;
%multi_num (num1=&amp;amp;base,multi=&amp;amp;base);
%do a=%eval(&amp;amp;expo-2) %to 1 %by -1;
%multi_num (num1=&amp;amp;ans,multi=&amp;amp;base);
%end;

%put Exponential Complete : &amp;amp;base. to the power of &amp;amp;expo. is &amp;amp;ans;
%mend;


%macro _29;

data results;
  length results $32767;

%do _first=2 %to 100;
  %let first_time= 1 ;
  %do _second=2 %to 100;

    %if &amp;amp;first_time = 1 %then
     %do;
      %multi_num (num1=&amp;amp;_first,multi=&amp;amp;_first);
       %let first_time=0;
     %end;
     %else
     %do;
      %multi_num (num1=&amp;amp;ans,multi=&amp;amp;_first);
     %end;
     results = "&amp;amp;ans.";
     output;

  %end;
%end;

run;

proc sort data = results nodupkey ;
  by results ;
run;

%let dsid=%sysfunc(open(results));
%let results=%sysfunc(attrn(&amp;amp;dsid,nlobs));
%let rc=%sysfunc(close(&amp;amp;dsid));

proc datasets lib=work nolist noprint;
  delete results;
run;quit;
  

%put Answer is: &amp;amp;results;

%mend;

%_29;

     







&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 04 Oct 2017 09:18:49 GMT</pubDate>
    <dc:creator>teelov</dc:creator>
    <dc:date>2017-10-04T09:18:49Z</dc:date>
    <item>
      <title>Distinct powers of integer combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/400882#M97179</link>
      <description>&lt;P&gt;Hello Folks, I thought it was about time i used SAS for some complex maths problems, as most of the time my main use for SAS is data manipulation. lately i've had some really nice problems to solve and in particular, help me grasp complex maths. but this particular exercise has me stumped, and i believe its due to the limitation of how i use SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;2&lt;SPAN&gt;=4, 2&lt;/SPAN&gt;3&lt;SPAN&gt;=8, 2&lt;/SPAN&gt;4&lt;SPAN&gt;=16, 2&lt;/SPAN&gt;5&lt;SPAN&gt;=32&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3&lt;/SPAN&gt;2&lt;SPAN&gt;=9, 3&lt;/SPAN&gt;3&lt;SPAN&gt;=27, 3&lt;/SPAN&gt;4&lt;SPAN&gt;=81, 3&lt;/SPAN&gt;5&lt;SPAN&gt;=243&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4&lt;/SPAN&gt;2&lt;SPAN&gt;=16, 4&lt;/SPAN&gt;3&lt;SPAN&gt;=64, 4&lt;/SPAN&gt;4&lt;SPAN&gt;=256, 4&lt;/SPAN&gt;5&lt;SPAN&gt;=1024&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;2&lt;SPAN&gt;=25, 5&lt;/SPAN&gt;3&lt;SPAN&gt;=125, 5&lt;/SPAN&gt;4&lt;SPAN&gt;=625, 5&lt;/SPAN&gt;5&lt;SPAN&gt;=3125&lt;/SPAN&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms: 4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125 How many distinct terms are in the sequence generated by ab for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is some sample code of how we are trying to solve the problem, the issue is, its taking 24hrs to run:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the issue could be that i'm not using multithreading as per datastep, so i considered casting the interger to an SQL box as we know SAS struggles with numbers beyond 15-16 characters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from some early calculations the dataset will end up with around 9800 rows, so i'm not sure where the bottleneck is&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro add_num (num1=,num2=);

%global ans;

%let len1 = %length(&amp;amp;num1);
%let len2 = %length(&amp;amp;num2);

%let maxlen = %sysfunc(max(&amp;amp;len1,&amp;amp;len2));

%if &amp;amp;maxlen ^= &amp;amp;len1 %then
  %let num1 = %sysfunc(repeat(0,%eval(&amp;amp;maxlen - &amp;amp;len1 - 1)))&amp;amp;num1;
%if &amp;amp;maxlen ^= &amp;amp;len2 %then
  %let num2 = %sysfunc(repeat(0,%eval(&amp;amp;maxlen - &amp;amp;len2 - 1)))&amp;amp;num2;

%let ten = 0;
%let ans = ;

%do i = &amp;amp;maxlen %to 1 %by -1;

  %let digit1 = %sysfunc(substr(&amp;amp;num1,&amp;amp;i,1));
  %let digit2 = %sysfunc(substr(&amp;amp;num2,&amp;amp;i,1));

  %let tmp = %eval(&amp;amp;digit1 + &amp;amp;digit2 + &amp;amp;ten);

  %if %length(&amp;amp;tmp) = 2 %then
  %do;
    %let unit = %sysfunc(substr(&amp;amp;tmp,2,1));
     %let ten = 1;
  %end;
  %else
  %do;
    %let unit = &amp;amp;tmp;
     %let ten = 0;    
  %end;

  %let ans = &amp;amp;unit&amp;amp;ans;

%end;

%if &amp;amp;ten = 1 %then 
  %let ans = &amp;amp;ten&amp;amp;ans;

/*%put Addition Complete : &amp;amp;num1 + &amp;amp;num2 = &amp;amp;ans;*/

%mend;

%macro multi_num(num1=,multi=);
%global ans;
%let num2 = &amp;amp;num1;
%let later = &amp;amp;num1;
%do j = 1 %to %eval(&amp;amp;multi - 1);
  %add_num(num1=&amp;amp;num1,num2=&amp;amp;num2);
  %let num1 = &amp;amp;ans;
%end;
/*%put Multiplication Complete : &amp;amp;num2 x &amp;amp;multi = &amp;amp;ans;*/
%mend;


%macro fact(factorial=);
%global ans;
%let ans = ;
%multi_num (num1=&amp;amp;factorial,multi=%eval(&amp;amp;factorial-1));
%do a=%eval(&amp;amp;factorial-2) %to 2 %by -1;
%multi_num (num1=&amp;amp;ans,multi=&amp;amp;a);
%end;

%put Factorial Complete : &amp;amp;factorial.! is &amp;amp;ans;
%mend;

%macro expo(base=,expo=);
%global ans;
%let ans = ;
%multi_num (num1=&amp;amp;base,multi=&amp;amp;base);
%do a=%eval(&amp;amp;expo-2) %to 1 %by -1;
%multi_num (num1=&amp;amp;ans,multi=&amp;amp;base);
%end;

%put Exponential Complete : &amp;amp;base. to the power of &amp;amp;expo. is &amp;amp;ans;
%mend;


%macro _29;

data results;
  length results $32767;

%do _first=2 %to 100;
  %let first_time= 1 ;
  %do _second=2 %to 100;

    %if &amp;amp;first_time = 1 %then
     %do;
      %multi_num (num1=&amp;amp;_first,multi=&amp;amp;_first);
       %let first_time=0;
     %end;
     %else
     %do;
      %multi_num (num1=&amp;amp;ans,multi=&amp;amp;_first);
     %end;
     results = "&amp;amp;ans.";
     output;

  %end;
%end;

run;

proc sort data = results nodupkey ;
  by results ;
run;

%let dsid=%sysfunc(open(results));
%let results=%sysfunc(attrn(&amp;amp;dsid,nlobs));
%let rc=%sysfunc(close(&amp;amp;dsid));

proc datasets lib=work nolist noprint;
  delete results;
run;quit;
  

%put Answer is: &amp;amp;results;

%mend;

%_29;

     







&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Oct 2017 09:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/400882#M97179</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2017-10-04T09:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct powers of integer combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/400884#M97181</link>
      <description>&lt;P&gt;Sorry, am really not understanding that formula.&amp;nbsp; What I will however say is that usinig global macro variables, and doing all the processing in macro is not the way forward.&amp;nbsp; If you can explain the formula, i can provide code, but almost any imaginable formula should be doable in a simple datastep, not sure why you have multiple macro calls in loops etc.&amp;nbsp; Just generating vast amounts of code.&amp;nbsp; Simplify your code using Base SAS.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 09:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/400884#M97181</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-04T09:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct powers of integer combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/400902#M97192</link>
      <description>&lt;P&gt;when you run the code for a small amount, lets say 20 - then in the log you can see what my macro is doing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Addition Complete : 4 + 4 = 8&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Addition Complete : 8 + 4 = 12&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Addition Complete : 12 + 04 = 16&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Multiplication Complete : 4 x 4 = 16&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Addition Complete : 16 + 16 = 32&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Addition Complete : 32 + 16 = 48&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Addition Complete : 48 + 16 = 64&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Multiplication Complete : 16 x 4 = 64&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Addition Complete : 64 + 64 = 128&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Addition Complete : 128 + 064 = 192&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Addition Complete : 192 + 064 = 256&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Multiplication Complete : 64 x 4 = 256&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Addition Complete : 256 + 256 = 512&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Addition Complete : 512 + 256 = 768&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Addition Complete : 768 + 256 = 1024&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;Multiplication Complete : 256 x 4 = 1024&lt;/FONT&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV class="sasSource"&gt;&lt;BR /&gt;put in a list, without checking whether they have already been obtained for the first time, all the terms that can be generated by \ (a ^ b \) by varying a and b from 2 to 100,remove all duplicates from this list,look at the number of term it stays in our list.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;i know this way is not optimal&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;for the bigger numbers we'd expect something like this&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;Multiplication Complete : 239072435685151324847153 x 17 = 4064231406647572522401601&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;after some research someone has done the following in python&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;PRE&gt;  powers = []
 for a in range (2, 101):
     for b in range (2, 101):
         powers.append (a ** b)
 #Suppresion of all duplicates in the powers list
 result = len (list (set (powers)))
 print (result) &lt;/PRE&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 04 Oct 2017 10:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/400902#M97192</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2017-10-04T10:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct powers of integer combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/400911#M97196</link>
      <description>&lt;P&gt;Along with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;I don't really understand what you're trying to do here but I agree that macro isn't the way forward&amp;nbsp;- if you can explain it more simply (ideally step by step for a couple of values) we can almost certainly supply code. For&amp;nbsp;example for this sort of computationally expensive calculation I'm thinking that storing the output initially in a hash object should be faster and would remove the need to de-duplicate at the end.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 11:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/400911#M97196</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-10-04T11:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct powers of integer combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/400962#M97218</link>
      <description>&lt;P&gt;First, let me give you a simple SAS program that (I think) handles your original case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data combinations;&lt;/P&gt;
&lt;P&gt;do a=2 to 5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do b=2 to 5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = a**b;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That gives you all the combinations.&amp;nbsp; Perhaps you are looking to subset that to get unique values for RESULT.&amp;nbsp; We know there will be duplicates, since 2**4 = 4**2.&amp;nbsp; Finding unique values is fairly easy, so we can skip that here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you get to the higher ranges you are talking about, as you noted you are going beyond SAS's capacity to store integers accurately.&amp;nbsp; You would have to revise the RESULT calculations to actually store the result in a different format.&amp;nbsp; For example, you might break down A and B into prime components and store the results as the combined powers for each prime component.&amp;nbsp; That's so wordy, I couldn't understand it if I read it.&amp;nbsp; So here is an example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a = 15, b = 36&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of storing 15**36, break down each component.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A:&amp;nbsp; components are 3 and 5, each raised to the first power.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;B:&amp;nbsp; components are 2 and 3, each raised to the second power.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you could have variables in your data set representing this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a_2 = 0, a_3 = 1, a_5 = 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since 36 = (2**2) * (3**2):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;b_2 = 2, b_3 = 2, b_5 = 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You just need to factor each number down to&amp;nbsp;the powers of its prime component.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since there are a limited number of prime numbers between 2 and 100, there are a limited number of variables to compute, with a reasonable range to their values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you need to compute the similar results for a**b.&amp;nbsp; I would need 2 cups of coffee before attempting that, but the idea is that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;result_2 = powers of 2 represented within a**b&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;result_3 = powers of 3 represented within a**b&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;result_5 = powers of 5 represented with a**b&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 13:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/400962#M97218</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-04T13:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct powers of integer combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/400997#M97229</link>
      <description>&lt;P&gt;You have explained it a lot better than i could, so thanks for that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the example at the top is using a max power of 5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which i think the code works for, so really its about my not using SAS correctly, or to my limitations of algorithms to get to the 100.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here are the results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 2 x 2 = 4&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 4 x 2 = 8&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 8 x 2 = 16&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 16 x 2 = 32&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 3 x 3 = 9&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 9 x 3 = 27&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 27 x 3 = 81&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 81 x 3 = 243&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 4 x 4 = 16&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 16 x 4 = 64&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 64 x 4 = 256&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 256 x 4 = 1024&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 5 x 5 = 25&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 25 x 5 = 125&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 125 x 5 = 625&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;Multiplication Complete : 625 x 5 = 3125&lt;/FONT&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="222222.PNG" style="width: 213px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15615i5185990F9A543FCA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="222222.PNG" alt="222222.PNG" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 14:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/400997#M97229</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2017-10-04T14:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct powers of integer combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/401010#M97233</link>
      <description>&lt;P&gt;Here's a hint: These sort of "math challenge" problems are usually constructed so that a brute force computation&amp;nbsp;will require a long time or will be numerically&amp;nbsp;infeasible. The key is usually to use mathematical ideas to reduce the complexity of the computations so that it is solvable quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For this problem,&amp;nbsp;I think you should use the&amp;nbsp;prime factorization theorem which states that each positive number can be expressed UNIQUELY as the&amp;nbsp;product of prime factors (up to the ordering of the factors).&amp;nbsp;&amp;nbsp;If I were to solve this problem, I would NEVER FORM any of the powers a**b, since that will overflow. Instead, I would represent each number in the range [2,100] by its unique&amp;nbsp;ordered prime factorization. (There are only 25 primes less than 100: {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}.)&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then use programmig and bookkeeping to count the number of distinct value of a**b.&amp;nbsp;I'll leave that effort to others.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 15:07:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/401010#M97233</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-10-04T15:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct powers of integer combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/401232#M97326</link>
      <description>&lt;P&gt;Thank you, this makes sense and gives me something to go on..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i will leave the post open for now as i could hit a few snags.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 08:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/401232#M97326</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2017-10-05T08:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct powers of integer combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/401349#M97372</link>
      <description>&lt;P&gt;How about this one ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data z;
do a=2 to 100;
 do b=2 to 100;
   value=b*log(a);output;
 end;
end;
run;

proc sql;
select count(distinct value) as n
 from z;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure SQL: 查询结果" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;n&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;9240&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 05 Oct 2017 14:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-powers-of-integer-combinations/m-p/401349#M97372</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-05T14:14:46Z</dc:date>
    </item>
  </channel>
</rss>

