<?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 call macro within dataset?! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-macro-within-dataset/m-p/809415#M319200</link>
    <description>&lt;P&gt;If the macro does not generate any SAS code then use the RESOLVE() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set ds_para ;
  result=resolve(cats('%macro2call(',catx(',',ind,indst,indend,sign),')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the macro generates SAS code then CANNOT return the results as if it was a function.&amp;nbsp; In that case look into use DOSUBL() function call so that the macro does not generate any SAS code in the current session.&lt;/P&gt;</description>
    <pubDate>Sat, 23 Apr 2022 03:51:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-04-23T03:51:05Z</dc:date>
    <item>
      <title>How to call macro within dataset?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-macro-within-dataset/m-p/809407#M319194</link>
      <description>&lt;P&gt;Say here is a dataset contain 10 rows, and each row contains parameters for calling a macro(return a value) ... how to make doable?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds_para;
input ind indst indend sign;
datalines;
1	 800 	1100 	-1
2	4000	5000	 1
3	6000	7000	-1
4	7500	8500	 1
5	9000	9500	-1
6	14000	15000	 1
7	18000	20000	-1
8	20500	21500	 1
9	22000	23000	-1
10	23000	24000	 1
10	24000	25000	-1
;run;quit;

%macro macro2call(ind, indst, indeend, sign);
.....
&amp;amp;ReturnVar
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Apr 2022 02:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-macro-within-dataset/m-p/809407#M319194</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-04-23T02:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to call macro within dataset?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-macro-within-dataset/m-p/809408#M319195</link>
      <description>&lt;P&gt;The best outcome would be a dataset with 10 rows, each has the ReturnVar&lt;/P&gt;</description>
      <pubDate>Sat, 23 Apr 2022 02:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-macro-within-dataset/m-p/809408#M319195</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-04-23T02:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to call macro within dataset?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-macro-within-dataset/m-p/809409#M319196</link>
      <description>&lt;P&gt;One approach is to use CALL EXECUTE like in this post: &lt;A href="https://communities.sas.com/t5/SAS-Programming/Assigning-value-to-a-macro-variable-within-a-datastep-without/m-p/809395#M319187" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Assigning-value-to-a-macro-variable-within-a-datastep-without/m-p/809395#M319187&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Apr 2022 02:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-macro-within-dataset/m-p/809409#M319196</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-04-23T02:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to call macro within dataset?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-macro-within-dataset/m-p/809412#M319199</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But somehow&amp;nbsp;&lt;CODE class=" language-sas"&gt;%let ReturnVar=%eval(&amp;amp;indst.+&amp;amp;indend.); complains?!&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand&lt;BR /&gt;is required. The condition was: indend+&lt;BR /&gt;3704 call execute(%macro2call(indst, indend));&lt;BR /&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;If&amp;nbsp;%let ReturnVar=%eval(5+8);&amp;nbsp;then&amp;nbsp;it&amp;nbsp;is&amp;nbsp;fine.&amp;nbsp;Confused&amp;nbsp;...&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds_para;
input ind indst indend sign;
datalines;
1	 800 	1100 	-1
2	4000	5000	 1
3	6000	7000	-1
4	7500	8500	 1
5	9000	9500	-1
6	14000	15000	 1
7	18000	20000	-1
8	20500	21500	 1
9	22000	23000	-1
10	23000	24000	 1
;run;quit;

%global ReturnVar;
%macro macro2call(ind, indst, indend, sign);
/*%let ReturnVar=%eval(5+8);  works*/
%let ReturnVar=%eval(&amp;amp;indst.+&amp;amp;indend.);/*?!*/
&amp;amp;ReturnVar
%mend;

data ds_para;
set  ds_para;
call execute(%macro2call(indst, indend));
mmind=&amp;amp;ReturnVar.;
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Apr 2022 02:52:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-macro-within-dataset/m-p/809412#M319199</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-04-23T02:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to call macro within dataset?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-macro-within-dataset/m-p/809415#M319200</link>
      <description>&lt;P&gt;If the macro does not generate any SAS code then use the RESOLVE() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set ds_para ;
  result=resolve(cats('%macro2call(',catx(',',ind,indst,indend,sign),')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the macro generates SAS code then CANNOT return the results as if it was a function.&amp;nbsp; In that case look into use DOSUBL() function call so that the macro does not generate any SAS code in the current session.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Apr 2022 03:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-macro-within-dataset/m-p/809415#M319200</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-23T03:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to call macro within dataset?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-macro-within-dataset/m-p/809416#M319201</link>
      <description>&lt;P&gt;Tom:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a huge. It indeed works. But how to save out the result on each call(the results are diff. but I can only save out the last call result).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* pass coln as para
call macro within dataset*/
data ds_para;
input ind indst indend sign;
datalines;
1	 800 	1100 	-1
2	4000	5000	 1
3	6000	7000	-1
4	7500	8500	 1
5	9000	9500	-1
6	14000	15000	 1
7	18000	20000	-1
8	20500	21500	 1
9	22000	23000	-1
10	23000	24000	 1
;run;quit;

data tempx;
do i=1 to 30000;
	x=ranuni(0);
	output;
end;
run;quit;
%global ReturnVar;
%macro test(ind, indst, indend, sign);
	%if &amp;amp;sign=-1 %then %do;
		proc sql noprint;
		select i into: ReturnVar
		from tempx
		where i between &amp;amp;indst. and &amp;amp;indend.
		having x=min(x);
		quit;
	%end;
	%if &amp;amp;sign= 1 %then %do;
		proc sql noprint;
		select i into: ReturnVar
		from tempx
		where i between &amp;amp;indst. and &amp;amp;indend.
		having x=max(x);
		quit;
	%end;
	%put "ReturnVar=&amp;amp;ReturnVar.";
%mend;

/*	works below: resolve() but only without "any" sas code
	DOSUBL() if sas code
*/
data want ;
  set ds_para ;
  /*result=resolve(cats('%test(',catx(',',ind,indst,indend,sign),')'));*/
  t=DOSUBL(cats('%test(',catx(',',ind,indst,indend,sign),')'));
  res="&amp;amp;ReturnVar.";
  result=put("&amp;amp;ReturnVar.",8.);
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Apr 2022 04:32:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-macro-within-dataset/m-p/809416#M319201</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-04-23T04:32:31Z</dc:date>
    </item>
  </channel>
</rss>

