<?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: Print whith FCMP in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614092#M179459</link>
    <description>&lt;P&gt;Provide an example of what you actually expect the output to look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you expect to get more than one value from a single function call then you have to provide a mechanism to pass the values. Your function is designed to pass in only one value and return only one as written.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at the documentation for OUTARGS on updating a number of variables and returning the updated values.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Dec 2019 15:39:21 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-12-27T15:39:21Z</dc:date>
    <item>
      <title>Print whith FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614073#M179450</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I want to print all values from this loop.&lt;/P&gt;&lt;P&gt;It's my code.&lt;/P&gt;&lt;P&gt;I have in result only the end value&lt;/P&gt;&lt;P&gt;Can you help me&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.pack1.finc1;
    function Myfunc1(var);
           
        do i =2 to int(sqrt(var));
        b=i;
        end;
       return (b);
    endsub;
quit;

options cmplib=work.pack1;

data _null_;
result=MyFunc1(100);
put result=;
run;




&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Dec 2019 13:36:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614073#M179450</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2019-12-27T13:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: Print whith FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614092#M179459</link>
      <description>&lt;P&gt;Provide an example of what you actually expect the output to look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you expect to get more than one value from a single function call then you have to provide a mechanism to pass the values. Your function is designed to pass in only one value and return only one as written.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at the documentation for OUTARGS on updating a number of variables and returning the updated values.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2019 15:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614092#M179459</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-27T15:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Print whith FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614123#M179472</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/121317"&gt;@mansour_ib_sas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A function is used to return ONE value at a time. Your&lt;BR /&gt;FCMP function between "do" and "end" cycles all values&lt;BR /&gt;between 2 and sqrt(var) and the final value at the end of the loop&lt;BR /&gt;as saved in B&amp;nbsp;is returned to the Data Step . So you are getting one value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to have all the values, you rewrite the function&lt;BR /&gt;to return one value. Use the Data Step to call the function&lt;BR /&gt;for each value of i between 2 to 100. Here is the revised&lt;BR /&gt;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.pack1.finc1;
    function Myfunc1(var);
           
        return(int(sqrt(var)));
         
    endsub;
quit;

options cmplib=work.pack1;

data _null_;
   do i = 2 to 100;
      result=MyFunc1(i);
      put result=;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Dec 2019 17:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614123#M179472</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-12-27T17:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Print whith FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614131#M179474</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/121317"&gt;@mansour_ib_sas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another look at your function based on the suggestion of&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A function can be made to return more than ONE Value provided you pass a _temporary_ array from the Data Set. The FCMP function can be made to fill the array and at the end pass the filled array to the Data Set. Passing array from the Data Step to the FCMP function which can pass the filled-array back to Data Step can be done using the keyword OUTARGS. Actually this keyword makes Data Step (see Array M[ ] ) to pass the address of M to share in FCMP Environment (See Array K[ ]). Any change in K reflects in M simultaneously. The FCMP function must return a value by definition. Hence, we return a dummy value, 1 in this case, which will be ignored in the Data Step as we are interested in the values of Array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OUTARGS for a FCMP function is undocumented. Usually it is used with SUBROUTINE. Here comes the function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.pack1.finc1;
    function Myfunc1(var, k[*]);
    outargs k;
           
        do i = 2 to int(sqrt(var));
         k[i] = i;
        end;
       return (1);
    endsub;
quit;

options cmplib=work.pack1;

data _null_;
   array m[100] _temporary_;
   result=MyFunc1(100, m);
   do i = 1 to dim(m);
       put m[i]=;
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;We do not know in advance how many values will be returned. In this case it can't be more than 10 as we take the square-root of 100 in the Function. So we size a _temporary_ array (M[ ]) with 10 in the Data Step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2019 18:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614131#M179474</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-12-27T18:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Print whith FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614180#M179477</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/121317"&gt;@mansour_ib_sas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just want to write the intermediary values to the SAS log for testing then adding a simple &lt;STRONG&gt;&lt;EM&gt;put b=;&lt;/EM&gt;&lt;/STRONG&gt; statement to the function would do the job.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.pack1.finc1;
  function Myfunc1(var);
    do i =2 to int(sqrt(var));
      b=i;
      put b=;
    end;
    return (b);
  endsub;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Dec 2019 01:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614180#M179477</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-12-28T01:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: Print whith FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614194#M179480</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/121317"&gt;@mansour_ib_sas&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Make the function character and return a string; then just print the result in the DATA step. Or parse the result If you want to create/print separate numeric values. For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib = work.pack1.func1;                                                                                                    
  function myfunc1 (var) $ ;                                                                                                            
    length r $ 32767 ;                                                                                                                  
    do i = 2 to sqrt (var) ;                                                                                                            
      r = catx (" ", r, i) ;                                                                                                            
    end ;                                                                                                                               
    return (r) ;                                                                                                                        
  endsub;                                                                                                                               
quit ;                                                                                                                                  
                                                                                                                                        
options cmplib = work.pack1 ;                                                                                                           
                                                                                                                                        
data _null_;                                                                                                                            
   result = myfunc1 (150) ;                                                                                                             
 * print the whole thing ;                                                                                                              
   put result ;                                                                                                                         
 * create a number and print separately ;                                                                                               
   do _n_ = 1 to countw (result) ;                                                                                                      
     num = input (scan (result, _n_), d.) ;                                                                                             
     put num ;                                                                                                                          
   end ;                                                                                                                                
run;          
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Dec 2019 06:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614194#M179480</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-12-28T06:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: Print whith FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614388#M179579</link>
      <description>&lt;P&gt;hello and thank you for all your responses;&lt;/P&gt;&lt;P&gt;My final objectif in this work is to detects Prime Numbres of others.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The error I made is not to stop the loop when the mod is 0.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I understood my error by debugging my program with your help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks again, i&lt;/SPAN&gt;&lt;SPAN&gt;f you have other suggestions, they are welcome.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.pack1.MyFunc1;
    function MyFunc1(var$) $10;
       length var1 $10;
        
        do i =2 to int(sqrt(var));
        if mod(var,i)=0 then do; var1="NbrNPre";leave;end;
        else do; var1="NbrPre";end;
        b= mod(var,i);
       
       put var=;
       put i=;
       put b=;
       
       
        end;
        
       return (var1);
    endsub;
quit;

data test;
input a;
cards;
34679
34678
23456789
; run;

options cmplib=work.pack1;

data test1;
set test;
    result=MyFunc1(a);
run;



&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 13:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-whith-FCMP/m-p/614388#M179579</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2019-12-30T13:42:23Z</dc:date>
    </item>
  </channel>
</rss>

