<?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: Using call execute with a macro function is not working properly in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920028#M44443</link>
    <description>&lt;P&gt;You can use a macro, but it would be more efficient IMO to have this be table driven than macro/string driven.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Create 4/5 empty tables with the desired structures, templates.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;For each table of interest, determine right comparison (same as now to some degree)&lt;/LI&gt;
&lt;LI&gt;Use PROC COMPARE or use sashelp.vcolumn and a merge to compare the variables presence&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Mar 2024 21:19:31 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2024-03-12T21:19:31Z</dc:date>
    <item>
      <title>Using call execute with a macro function is not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920001#M44434</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have created the follow varexist2 macro function, which send into temp if the various variable defined in varlist are present or not into the provide dataset name. Then the information is append into temp2 each time the macro function varexist2 is called.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alone, the call look like that.&lt;/P&gt;
&lt;P&gt;%varexist2(dsn2=temp.be_auto_prmaou2001);&lt;/P&gt;
&lt;P&gt;and I can make thousand of macro execution and it works fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I should be using a call execute like below:&lt;/P&gt;
&lt;P&gt;temp is only populated with dsn2 name. I am loosing the answers about if a variables exist or not into the datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First question how do we troubleshoot the call execute?&lt;/P&gt;
&lt;P&gt;How do we solve that issue?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto log='~/eg.log';
libname dest1 base '/.../data';
data prm_FILESLST_SPDS9 (drop=text cfname);
set dest1.FILESLST_SPDS9;
if index(fname,'prm') = 0 then delete;
if index(fname,'raw') &amp;gt; 0 then delete;
if index(fname,'_ab_') &amp;gt; 0 then delete;
if index(text,'/test/') &amp;gt; 0 then delete;
if index(path,'/vd/') &amp;gt; 0 then delete;
if cie = 'sa' then delete;
process='HYFI';
where category eq 'prime';
run;
data prm_FILESLST_SPDS9 ;
set prm_FILESLST_SPDS9 ;
path2=scan(path,6,'/');
if path2 ne '' then delete;
run;

proc sort data=prm_FILESLST_SPDS9 (drop=path2) nodupkey out=HYFI_prime;
by path fname;
run;
proc sql;
create table valid_HYFI_prime as
select *, count(fname) as count
from HYFI_prime
group by fname
having count(fname) &amp;gt; 1;
quit;
data valid_HYFI_prime;
set valid_HYFI_prime;
run;
data dest1.HYFI_prime;
retain process path fname subfolder hub extension path_n_fname cie lob category type; 
set HYFI_prime;
run;
data HYFI_prime;
set dest1.HYFI_prime;
run;

data test;
set HYFI_prime;
if index(fname,'prm') = 0 then output test;
run;

%let Cl_auto_prm_varlst=AGREEMENT_NBR APPLICATION_ID BUSINESS_SOURCE_CD COMPANY_CD DISTRIBUTION_COMPANY_CD GC_COVER_CATEGORY_CD OBJECT_TYPE 
                        POLICY_EXPIRY_DT POLICY_INCEPTION_DT POLICY_TYPE_TR PROVINCE_CD TRANSACTION_CD_SUMMARY;
%let Cl_prop_prm_varlst=AGREEMENT_NBR APPLICATION_ID BROKER_NBR BUSINESS_SOURCE_CD COMPANY_CD DISTRIBUTION_COMPANY_CD OBJECT_TYPE 
                        POLICY_EXPIRY_DT POLICY_INCEPTION_DT POLICY_TYPE_TR PROVINCE_CD REINSURER_CD TRANSACTION_CD_SUMMARY;

%let Ha_auto_prm_varlst=AGREEMENT_NBR BROKER_FMT_GC BUSINESS_SOURCE_CD COMPANY_CD POLICY_EXPIRY_DT POLICY_INCEPTION_DT POLICY_TYPE_CD 
                        RISK_PROVINCE_CD RISK_TYPE_CD TRANSACTION_CD_SUMMARY;
%let Ha_prop_prm_varlst=AGREEMENT_NBR BROKER_FMT_GC BUSINESS_SOURCE_CD COMPANY_CD POLICY_EXPIRY_DT POLICY_INCEPTION_DT POLICY_TYPE_CD PREMIUM_TRANSACTION_CD 
                        REINSURANCE_TREATY POLICY_PROVINCE_CD RISK_CLASS SECTOR_CD TRANSACTION_CD_SUMMARY;

 data  temp2;
 set _null_;
 run;

%macro varexist2(dsn2=) ;
%global Cl_auto_prm_varlst Cl_prop_prm_varlst Ha_auto_prm_varlst Ha_prop_prm_varlst varlist;
 data temp;
 run;

%IF %SUBSTR(&amp;amp;DSN2.,9,4) eq auto %then 
	%do;
		%let subfolder=%str(auto);
		%let year=%SUBSTR(&amp;amp;DSN2.,20,4);
		%let month=%SUBSTR(&amp;amp;DSN2.,17,3);
		%let cie=%SUBSTR(&amp;amp;DSN2.,6,2);		
		%if (&amp;amp;cie. eq be) or (&amp;amp;cie. eq gc) or (&amp;amp;cie. eq gp) %then %let varlist=&amp;amp;Cl_auto_prm_varlst.;
		%else %let varlist=&amp;amp;Ha_auto_prm_varlst.;
	%end;
%ELSE %IF %SUBSTR(&amp;amp;DSN2.,9,4) eq prop %then 
	%do;
		%let subfolder=%str(habi);
        %let year=%SUBSTR(&amp;amp;DSN2.,20,4);
		%let month=%SUBSTR(&amp;amp;DSN2.,17,3);
		%let cie=%SUBSTR(&amp;amp;DSN2.,6,2);
		%if (&amp;amp;cie. eq be) or (&amp;amp;cie. eq gc) or (&amp;amp;cie. eq gp) %then %let varlist=&amp;amp;Cl_prop_prm_varlst.;
		%else %let varlist=&amp;amp;Ha_prop_prm_varlst.;
	%end;
%ELSE %IF %SUBSTR(&amp;amp;DSN2.,9,3) = cna %then 
	%do;
	    
		%let subfolder=%str(entr);
		%let year=%SUBSTR(&amp;amp;DSN2.,19,4);
		%let month=%SUBSTR(&amp;amp;DSN2.,16,3);
		%let cie=%SUBSTR(&amp;amp;DSN2.,6,2);
		%if (&amp;amp;cie. eq be) or (&amp;amp;cie. eq gc) or (&amp;amp;cie. eq gp) %then %let varlist=&amp;amp;Cl_prop_prm_varlst.;
	%end;

/*%put &amp;amp;=cie &amp;amp;=subfolder &amp;amp;=month. &amp;amp;=year &amp;amp;=varlist.;*/
libname temp spde "/dwh_actuariat/sasdata/sas&amp;amp;year./&amp;amp;cie./&amp;amp;subfolder./";
/*%put %sysfunc(pathname(TEMP));*/

%local dsid vnum;


%do i=1 %to %sysfunc(countw(&amp;amp;varlist.));
	%let var&amp;amp;i=%scan(&amp;amp;varlist.,&amp;amp;i);
%end;

data temp;
set temp;

%let dsid = %sysfunc(open(&amp;amp;dsn2));
%if &amp;amp;dsid %then 
%do;
		    
			%do j=1 %to %sysfunc(countw(&amp;amp;varlist.));
				%let vnum&amp;amp;j=%sysfunc(varnum(&amp;amp;dsid,&amp;amp;&amp;amp;var&amp;amp;j));
				%if &amp;amp;&amp;amp;vnum&amp;amp;j &amp;gt; 0 %then 
				%do;
					%scan(&amp;amp;varlist.,&amp;amp;j) = 'Y';;
				%end;
				%else 
				%do;
					%scan(&amp;amp;varlist.,&amp;amp;j) ='N';;
				%end;
			%end;
%let dsid = %sysfunc(close(&amp;amp;dsid));		
%end; 
run;
data temp;
length fname2 $35.;
set temp;
fname2="&amp;amp;dsn2.";
run;

data temp2;
set temp temp2;
run;

%put &amp;amp;dsn2.;
%mend varexist2;

/*%varexist2(dsn2=temp.be_auto_prmaou2001);*/

/*data HYFI_prime;*/
data test2 (keep=txt fname);
length txt $100.;
set HYFI_prime (obs=36);
txt=COMPRESS(cats('%varexist2(dsn2=temp.',fname,');'));
run;

data _null_;
set test2;
call execute('%varexist2(dsn2=temp.'||strip(fname)||');');        
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 19:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920001#M44434</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-03-12T19:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using call execute with a macro function is not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920004#M44436</link>
      <description>&lt;P&gt;Try using &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_048/lefunctionsref/p09dcftd1xxg1kn1brnjyc0q93yk.htm" target="_self"&gt;DOSUBL&lt;/A&gt; instead.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 19:43:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920004#M44436</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-03-12T19:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using call execute with a macro function is not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920006#M44437</link>
      <description>&lt;P&gt;Debug macros using the system options MPRINT MLOGIC (if branches in code aren't working as expected) SYMBOLGEN (if getting unexpected names and such generated).&lt;/P&gt;
&lt;P&gt;Then look at the LOG for where odd things happen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then share the pertinent part of the Log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will say that looking for part of a parameter to be in specific locations of a parameter string is very likely to be fragile, thos %substr(&amp;amp;DSN2&amp;nbsp;&amp;nbsp; ) calls.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You make a data set TEST2 with a variable named TXT that appears to hold the text that you want to use for call execute. Then when you use Test2 you rebuild a string for call execute.&lt;/P&gt;
&lt;P&gt;Why not:&amp;nbsp; Call execute(txt);&lt;/P&gt;
&lt;P&gt;Did you not make TXT long enough to hold all the parameters? Have you examined the values of TXT in your Test2 set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another common option is instead of CALL Execute is to create your string of the command, such as TXT. Then write it to a text file using a data step. Then %include that file to execute it.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 20:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920006#M44437</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-12T20:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using call execute with a macro function is not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920009#M44439</link>
      <description>You certainly have timing issues.&lt;BR /&gt;&lt;BR /&gt;Remember, when calling a macro with call execute, all the macro code is executed immediately.&lt;BR /&gt;&lt;BR /&gt;The macro you’ve provided also contains non macro code, which gets added to the call stack and executed when the datastep terminates.&lt;BR /&gt;&lt;BR /&gt;You can also try delaying the macro call with a quoting function such as %nrstr&lt;BR /&gt;&lt;BR /&gt;eg: call execute (‘%nrstr(&amp;lt;your macro call&amp;gt;’)’);</description>
      <pubDate>Tue, 12 Mar 2024 20:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920009#M44439</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-12T20:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using call execute with a macro function is not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920011#M44440</link>
      <description>Are you trying to add variables to a dataset to meet a standard in case it doesn't have all the required variables, with 4 different iterations?</description>
      <pubDate>Tue, 12 Mar 2024 20:10:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920011#M44440</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-03-12T20:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using call execute with a macro function is not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920018#M44442</link>
      <description>&lt;P&gt;Yes temp should look like that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;fname2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;agreement_nbr&amp;nbsp; &amp;nbsp;...&amp;nbsp; &amp;nbsp; &amp;nbsp;transaction_cd_summary&lt;/P&gt;
&lt;P&gt;temp.be_auto_prmaug2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then this temp file is append into temp2 for each macro function call&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 20:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920018#M44442</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-03-12T20:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using call execute with a macro function is not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920028#M44443</link>
      <description>&lt;P&gt;You can use a macro, but it would be more efficient IMO to have this be table driven than macro/string driven.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Create 4/5 empty tables with the desired structures, templates.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;For each table of interest, determine right comparison (same as now to some degree)&lt;/LI&gt;
&lt;LI&gt;Use PROC COMPARE or use sashelp.vcolumn and a merge to compare the variables presence&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 21:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-call-execute-with-a-macro-function-is-not-working-properly/m-p/920028#M44443</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-03-12T21:19:31Z</dc:date>
    </item>
  </channel>
</rss>

