<?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: FCMP - How to pass permanent array values to user defined function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/FCMP-How-to-pass-permanent-array-values-to-user-defined-function/m-p/532444#M145892</link>
    <description>&lt;P&gt;I added several dimensions to be closer to you need. Does this help you more?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp trace flow outlib=WORK.USERFUNCS.EX;
  function sumarray(ARR[*,*],ROW) ;
    do I = 1 to 3;
      TOT = sum(TOT, ARR[ROW,I]); 
    end;
    return(TOT);
  endsub;
run;

options cmplib=WORK.USERFUNCS; 

data _null_;
  array DYS[2,3] (1 2 3 4 5 6);        
  W = sumarray(DYS,2);
  putlog W=; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;W=15&lt;/P&gt;</description>
    <pubDate>Sun, 03 Feb 2019 20:33:12 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-02-03T20:33:12Z</dc:date>
    <item>
      <title>FCMP - How to pass permanent array values to user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-How-to-pass-permanent-array-values-to-user-defined-function/m-p/531553#M145499</link>
      <description>&lt;P&gt;I need to create a string of numbers in a very specific way and calling a function where I pass different parameter values seems the easiest way.&amp;nbsp; I discovered proc fcmp and got it mostly working except that it only works with temporary arrays and I can't figure out a work-around.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data would be like&lt;/P&gt;&lt;P&gt;obs1 101 001 001&lt;/P&gt;&lt;P&gt;obs2 010 100 101&lt;/P&gt;&lt;P&gt;obs3 100 010&amp;nbsp; 010&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here is an example of what I might want as output. I want to be able to manipulate each cluster of numbers differently.&lt;/P&gt;&lt;P&gt;obs1 10 001 01&lt;/P&gt;&lt;P&gt;obs2 01 100 01&lt;/P&gt;&lt;P&gt;obs3 10 010 10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data is stored in variables that match a 2 dimensional array. And the actual number of values per cluster varies.&amp;nbsp; My idea to accomplish this is to nest user-defined functions within the cats function.&amp;nbsp; But I need a way to pass the numbers to the function in a practical way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this function colim, det is the array.&amp;nbsp; If I create a temporary array (dys) from the main data, this works, but that doesn't accomplish what I want to do.&amp;nbsp; Passing just the variables doesn't work, and passing values as part of a permanent array doesn't work (not sure my syntax is right here).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought about creating another function (or macro) to create the temporary array but I am not sure how to make that work.&amp;nbsp; It still has the temporary array problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;*In this example, det is the array; &lt;/CODE&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp trace flow outlib=sasuser.userfuncs.ex;
FUNCTION colim(syr , eyr , cdet $, det[*]) $ 12;
length histi $12;
tot = 0;
if eyr = 0 then histi=' ';
else do i=syr to (eyr - 1);
     tot = tot + det[i]; 
   end;
   if tot ge 1 then col = '1';
   histi= cats(col, cdet);

   return(histi);
endsub;

*if I set up a temporary array-dys, - this works, but I need to be able to &lt;BR /&gt;  pull different subsets from tdays in the same concatenation;

data tmp2;
   set tmp1;
   array tdays {11,10}  yr06d1 - yr06d10 yr07d1 - yr07d10 yr08d1 - yr08d10 &lt;BR /&gt;                        yr09d1-yr09d10 yr10d1-yr10d10 yr11d1-yr11d10 yr12d1-yr12d10 &lt;BR /&gt;                        yr13d1-yr13d10 yr14d1-yr14d10 yr15d1-yr15d10 yr16d1-yr16d10;

   array dys(10) _temporary_;
   do i=1 to 10;
      dys(i) = tdays(2,i);
   end; 
   *this works but doesn't accomplish what I need;&lt;BR /&gt;   w = cats(colim('abc', 1, 6, yr07d6, dys), colim('abc', 2, 6, yr07d1, dys), 'x' ); 
   **these don't work;&lt;BR /&gt;   w = cats(colim('abc', 1, 6, yr06d6, yr06d1 - yr06d10), colim('abc', 3, 8, yr07d1, yr07d1 - yr07d10), 'x' ); 
   w = cats(colim('abc', 1, 6, yr06d6, tdays[*]yr06), colim('abc', 3, 8, tdays[*]yr07), 'x' ); 
&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am using SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 05:44:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-How-to-pass-permanent-array-values-to-user-defined-function/m-p/531553#M145499</guid>
      <dc:creator>Sascoder</dc:creator>
      <dc:date>2019-01-31T05:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP - How to pass permanent array values to user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-How-to-pass-permanent-array-values-to-user-defined-function/m-p/531860#M145668</link>
      <description>&lt;P&gt;Always reduce your problems to the simplest form and then search.&lt;/P&gt;
&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp trace flow outlib=WORK.USERFUNCS.EX;
  function sumarray(ARR[*]) ;
    do I = 1 to dim(ARR);
       TOT = sum(TOT, ARR[I]); 
     end;
    return(TOT);
  endsub;
run;

options cmplib=WORK.USERFUNCS; 

data _null_;
  array DYS[3] _temporary_ (1 2 3);        
  W = sumarray(DYS);
  putlog W=; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;W=6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 02:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-How-to-pass-permanent-array-values-to-user-defined-function/m-p/531860#M145668</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-02-01T02:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP - How to pass permanent array values to user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-How-to-pass-permanent-array-values-to-user-defined-function/m-p/531883#M145674</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;This solution doesn't generate the 01 strings.&amp;nbsp; It gives a sum.&lt;/P&gt;&lt;P&gt;I need to generate 01 strings from source 01 strings based on varied and situation specific conditions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 05:07:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-How-to-pass-permanent-array-values-to-user-defined-function/m-p/531883#M145674</guid>
      <dc:creator>Sascoder</dc:creator>
      <dc:date>2019-02-01T05:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP - How to pass permanent array values to user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-How-to-pass-permanent-array-values-to-user-defined-function/m-p/531889#M145676</link>
      <description>Adapt it. I pass an array and process it.You can do the same. &lt;BR /&gt;</description>
      <pubDate>Fri, 01 Feb 2019 05:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-How-to-pass-permanent-array-values-to-user-defined-function/m-p/531889#M145676</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-02-01T05:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP - How to pass permanent array values to user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-How-to-pass-permanent-array-values-to-user-defined-function/m-p/532444#M145892</link>
      <description>&lt;P&gt;I added several dimensions to be closer to you need. Does this help you more?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp trace flow outlib=WORK.USERFUNCS.EX;
  function sumarray(ARR[*,*],ROW) ;
    do I = 1 to 3;
      TOT = sum(TOT, ARR[ROW,I]); 
    end;
    return(TOT);
  endsub;
run;

options cmplib=WORK.USERFUNCS; 

data _null_;
  array DYS[2,3] (1 2 3 4 5 6);        
  W = sumarray(DYS,2);
  putlog W=; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;W=15&lt;/P&gt;</description>
      <pubDate>Sun, 03 Feb 2019 20:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-How-to-pass-permanent-array-values-to-user-defined-function/m-p/532444#M145892</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-02-03T20:33:12Z</dc:date>
    </item>
  </channel>
</rss>

