<?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: Proc fcmp : Issue with run_macro resolution in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-fcmp-Issue-with-run-macro-resolution/m-p/778850#M247976</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;You guys are awesome!&amp;nbsp; This has worked brilliantly. Can't thank you enough.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Didn't knew that we could nest the %sysfunc in this manner.&lt;/P&gt;</description>
    <pubDate>Fri, 05 Nov 2021 17:17:10 GMT</pubDate>
    <dc:creator>r_behata</dc:creator>
    <dc:date>2021-11-05T17:17:10Z</dc:date>
    <item>
      <title>Proc fcmp : Issue with run_macro resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-fcmp-Issue-with-run-macro-resolution/m-p/778810#M247951</link>
      <description>&lt;P&gt;I have a list of sas dataset names (absolute paths) stored in a sas dataset. All I am trying to get the number of observations for each of the dataset by passing the name of the dataset as an argument to a custom function created using sas fcmp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While below is not the actual code, it is somewhat similar to this :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro getobs;
	%let id=%sysfunc(open(&amp;amp;dsn));
	%let no=%sysfunc(attrn(&amp;amp;id.,nobs));
	%let rc=%sysfunc(close(&amp;amp;id.));
%mend;

proc fcmp outlib = work.functions.func;
	function no_of_obs(dsn);
		no=run_macro('getobs',dsn);
		return (no);
	endsub;
run;

options cmplib=work.functions;

data _null_;
	rc=no_of_obs("sashelp.class");
	put rc=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I suspect there is a timing issue with the macro involved , but cannot wrap my head around it. Any help is appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the log :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;29         
30         options cmplib=work.functions;
31         
32         data _null_;
33         	rc=no_of_obs("sashelp.class");
34         	put rc=;
35         run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
2                                                          The SAS System                             09:36 Friday, November 5, 2021

      33:15   
NOTE: Invalid numeric data, 'sashelp.class' , at line 33 column 15.
1                                                          The SAS System                             10:38 Friday, November 5, 2021

WARNING: Argument 1 to function ATTRN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
rc=0
rc=0 _ERROR_=1 _N_=1
&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Nov 2021 15:41:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-fcmp-Issue-with-run-macro-resolution/m-p/778810#M247951</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2021-11-05T15:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc fcmp : Issue with run_macro resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-fcmp-Issue-with-run-macro-resolution/m-p/778817#M247958</link>
      <description>&lt;P&gt;The first thing you should repair is that the function expects a numeric input. Put a $ after dsn to make the function accept a character input.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 15:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-fcmp-Issue-with-run-macro-resolution/m-p/778817#M247958</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-11-05T15:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc fcmp : Issue with run_macro resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-fcmp-Issue-with-run-macro-resolution/m-p/778832#M247970</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223452"&gt;@r_behata&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition to the missing $ sign in the definition of the function, as pointed out by Peter, I think you need to change the first %LET statement in the macro to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let id=%sysfunc(open(%sysfunc(dequote(&amp;amp;dsn))));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in order to temporarily remove the quotes around the function argument.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the RUN_MACRO function should have a variable name as the third argument that corresponds to the macro variable which contains the value to be returned:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rc=run_macro('getobs',dsn,no);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Nov 2021 16:24:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-fcmp-Issue-with-run-macro-resolution/m-p/778832#M247970</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-11-05T16:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc fcmp : Issue with run_macro resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-fcmp-Issue-with-run-macro-resolution/m-p/778850#M247976</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;You guys are awesome!&amp;nbsp; This has worked brilliantly. Can't thank you enough.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Didn't knew that we could nest the %sysfunc in this manner.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 17:17:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-fcmp-Issue-with-run-macro-resolution/m-p/778850#M247976</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2021-11-05T17:17:10Z</dc:date>
    </item>
  </channel>
</rss>

