<?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: How to use call dynamic_array right? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-call-dynamic-array-right/m-p/610921#M18164</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270406"&gt;@whymath&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue here is that OF operator for a Dynamically created Array in FCMP which is NOT supported. There are two ways to solve your problem - one using Dynamic array and the other without it. In the former, we compare absolute difference of the previous and the current to choose the minimum. In the second we use MIN function to choose the minimum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let us see the first solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc fcmp outlib = work.funcs.Math;
    function MinDis(Exp,Arr[*]);
        array dis[1] / nosym;
        call dynamic_array(dis,dim(Arr));
        mindis = constant('BIG');
        do i = 1 to dim(Arr);
            dis[i] = abs((Exp - Arr[i]));
            if mindis &amp;gt; dis[i] then mindis = dis[i]; * get minimum distance;
        end;
        return(mindis);
    endsub;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NOSYM is a short form for NOSYMBOLS. MINDIS is assigned to an impossible big positive value as Minimum Distance. Each absolute difference is compared to previous to get the current minimum. Finally, MINDIS has the final minimum value which is returned to the Data Step. The array DIS[ ] is a waste of memory and hence the second solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second solution avoids the use of the array, DIS[ ] but uses the _temporary_ array passed by the Data Step. Here we compare the previous MINDIS with the i-th absolute difference to choose the minimum value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/** No Dynamic_Array **/

proc fcmp outlib = work.funcs.Math;
    function MinDis(Exp,Arr[*]);
        mindis = Constant('BIG');
        do i = 1 to dim(Arr);
            mindis = min(mindis, abs(Exp - Arr[i]));
        end;
        return(mindis);
    endsub;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this answers your question.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Dec 2019 08:50:45 GMT</pubDate>
    <dc:creator>KachiM</dc:creator>
    <dc:date>2019-12-11T08:50:45Z</dc:date>
    <item>
      <title>How to use call dynamic_array right?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-call-dynamic-array-right/m-p/610698#M18143</link>
      <description>&lt;DIV class="votecell post-layout--left"&gt;&lt;DIV class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200"&gt;&lt;DIV class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center"&gt;I have try to write a user-defined function&amp;nbsp;&lt;CODE&gt;MinDis()&lt;/CODE&gt;&amp;nbsp;and apply it in data step, this function is used to compute the minimum distance from one point to each element of an (numeric)array. Code fllowing:&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="postcell post-layout--right"&gt;&lt;DIV class="post-text"&gt;&lt;PRE&gt;&lt;CODE&gt;proc fcmp outlib = work.funcs.Math;
    function MinDis(Exp,Arr[*]);
        array dis[2] /nosymbols;
        call dynamic_array(dis,dim(Arr));
        do i = 1 to dim(Arr);
            dis[i] = abs((Exp - Arr[i]));
        end;
        return(min(of dis[*]));
    endsub;
quit;

option cmplib=work.funcs ; 

data MinDis;
    input LamdazLower LamdazUpper @;
    cards;
    2.50 10.0
    2.51 10.8
    2.49 9.97
    2.75 9.50
    ;
run;

data _null_;
    set ;

    array _PTN_ [14] _temporary_ (0.5,1,1.5,2,2.5,3,4,5,6,7,8,9,10,12);
    StdLamZLow = MinDis(LamdazLower,_PTN_);
    StdLamZUpp = MinDis(LamdazUpper,_PTN_);
    put _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It was compile rightly but gave wrong results.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;StdLamZLow&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;just get the minimum distance from&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;LamdazLower&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to the first two element of array&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;_PTN_&lt;/CODE&gt;.&lt;/P&gt;&lt;P&gt;When I rewrite the dim of&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;dis&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;as 999 or something very big and get rid of&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;call dynamic_array&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;statement I would get it right. But I surely want to know why&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;min(of dis[*])&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;just take&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;dis&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;as a 2-dim array.&lt;/P&gt;&lt;P&gt;By the way, how can I use implied DO-loops&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;do over ...&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to instead of explicit DO loops? I have tried several times but haven`t success yet.&lt;/P&gt;&lt;P&gt;Thanks for any hints.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 10 Dec 2019 14:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-call-dynamic-array-right/m-p/610698#M18143</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2019-12-10T14:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to use call dynamic_array right?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-call-dynamic-array-right/m-p/610710#M18144</link>
      <description>&lt;P&gt;A few things:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- What is your desired result given _PIN_? Probably makes it easier to help you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- I assume that you misspelled &lt;EM&gt;nosymbols&lt;/EM&gt; as &lt;EM&gt;symbols&lt;/EM&gt; in your Array Statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- You should always use the &lt;A href="https://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=n10vesidziklh1n1l7kidq4dqd0r.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p1ru8ksyfhgovan162zf0kj06b0k" target="_self"&gt;Varargs Option&lt;/A&gt; when you want the function to accept a variable number of arguments (like an array)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Do Over syntax is for implicit arrays only. PROC FCMP does not support implicit arrays.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 13:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-call-dynamic-array-right/m-p/610710#M18144</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-12-10T13:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to use call dynamic_array right?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-call-dynamic-array-right/m-p/610744#M18145</link>
      <description>&lt;P&gt;1 The desired result of &lt;STRONG&gt;StdLamZLow&lt;/STRONG&gt; should be the minimum distance from &lt;STRONG&gt;LamdazLower&amp;nbsp;&lt;/STRONG&gt;to each element of array &lt;STRONG&gt;_PTN_&lt;/STRONG&gt;, that is minimum of &lt;STRONG&gt;(abs(LamdazLower-_PTN_[i]))&lt;/STRONG&gt;, am I more clear now?&lt;/P&gt;&lt;P&gt;2. Yes, I misspelled the option&amp;nbsp;&lt;EM&gt;nosymbols.&amp;nbsp;&lt;/EM&gt;Now it is corrected.&lt;/P&gt;&lt;P&gt;3. I don't realize it is neccessary cause I just get an rig&lt;/P&gt;&lt;P&gt;4. Thank you for the fourth tip.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 14:58:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-call-dynamic-array-right/m-p/610744#M18145</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2019-12-10T14:58:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to use call dynamic_array right?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-call-dynamic-array-right/m-p/610921#M18164</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270406"&gt;@whymath&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue here is that OF operator for a Dynamically created Array in FCMP which is NOT supported. There are two ways to solve your problem - one using Dynamic array and the other without it. In the former, we compare absolute difference of the previous and the current to choose the minimum. In the second we use MIN function to choose the minimum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let us see the first solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc fcmp outlib = work.funcs.Math;
    function MinDis(Exp,Arr[*]);
        array dis[1] / nosym;
        call dynamic_array(dis,dim(Arr));
        mindis = constant('BIG');
        do i = 1 to dim(Arr);
            dis[i] = abs((Exp - Arr[i]));
            if mindis &amp;gt; dis[i] then mindis = dis[i]; * get minimum distance;
        end;
        return(mindis);
    endsub;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NOSYM is a short form for NOSYMBOLS. MINDIS is assigned to an impossible big positive value as Minimum Distance. Each absolute difference is compared to previous to get the current minimum. Finally, MINDIS has the final minimum value which is returned to the Data Step. The array DIS[ ] is a waste of memory and hence the second solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second solution avoids the use of the array, DIS[ ] but uses the _temporary_ array passed by the Data Step. Here we compare the previous MINDIS with the i-th absolute difference to choose the minimum value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/** No Dynamic_Array **/

proc fcmp outlib = work.funcs.Math;
    function MinDis(Exp,Arr[*]);
        mindis = Constant('BIG');
        do i = 1 to dim(Arr);
            mindis = min(mindis, abs(Exp - Arr[i]));
        end;
        return(mindis);
    endsub;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this answers your question.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2019 08:50:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-call-dynamic-array-right/m-p/610921#M18164</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-12-11T08:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to use call dynamic_array right?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-call-dynamic-array-right/m-p/629814#M20782</link>
      <description>Very impressive. thanks a lot.</description>
      <pubDate>Thu, 05 Mar 2020 14:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-call-dynamic-array-right/m-p/629814#M20782</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2020-03-05T14:17:39Z</dc:date>
    </item>
  </channel>
</rss>

