<?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: Conditionally execute a macro based on proc sql into var? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255689#M309872</link>
    <description>&lt;P&gt;You refer to obs_count instead of the macro variable &amp;amp;obs_count?&lt;/P&gt;</description>
    <pubDate>Wed, 09 Mar 2016 22:43:45 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-03-09T22:43:45Z</dc:date>
    <item>
      <title>Conditionally execute a macro based on proc sql into var?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255686#M309871</link>
      <description>&lt;P&gt;Hello I need to conditionally execute a second sas program only if&amp;nbsp;I have one or more obs in a data set of path\files searching for metadata?&amp;nbsp; This is what I have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select 
	count(*) into: obs_count
from list_of_files;  /*zero, one or many fully qualified path names like C:\mypath\myfile.mdb where databasetype is set to mdb below, and pname is set to my program path*/
quit;
;
%put "&amp;amp;pname.file-inventories-&amp;amp;databasetype..Part2.sas";
%macro check_if_need_to_run;
	%if ( obs_count ne 0 ) %then %do;
	    %put &amp;amp;obs_count;
		%include "&amp;amp;pname.file-inventories-&amp;amp;databasetype..Part2.sas";
	%end;
 	%else %do;
		%put "No &amp;amp;pname.file-inventories-&amp;amp;databasetype..Part2.sas data to process";
	%end;
%mend check_if_need_to_run;
%check_if_need_to_run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...at this point it is executing no mater what.&amp;nbsp; Can anyone give me a pointer?&amp;nbsp; TIA.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 22:37:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255686#M309871</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2016-03-09T22:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally execute a macro based on proc sql into var?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255689#M309872</link>
      <description>&lt;P&gt;You refer to obs_count instead of the macro variable &amp;amp;obs_count?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 22:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255689#M309872</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-09T22:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally execute a macro based on proc sql into var?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255690#M309873</link>
      <description>&lt;P&gt;If this isn't a typo when posting:&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token macrostatement"&gt;%if&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt; obs_count &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%then&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token punctuation"&gt;it should be&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token macrostatement"&gt;%if&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt; &lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;obs_count &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%then&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 22:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255690#M309873</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-09T22:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally execute a macro based on proc sql into var?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255695#M309875</link>
      <description>&lt;P&gt;I had tried that once, I must have had two bugs in it at once and took it back out.&amp;nbsp;&amp;nbsp; Thanks for the typo catch.&amp;nbsp; Since you were first to reply&amp;nbsp;you get the resolve.&amp;nbsp;&amp;nbsp; Sorry to both of you for such a dumb question. Still green behind the ears with SAS.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 22:57:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255695#M309875</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2016-03-09T22:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally execute a macro based on proc sql into var?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255744#M309876</link>
      <description>&lt;P&gt;Out of interest, why? &amp;nbsp;To my mind a process should execute fully though the whole code, the only thing which would change is the output itself.&lt;/P&gt;
&lt;P&gt;However if you must do it this way:&lt;/P&gt;
&lt;PRE&gt;data _null_;
&amp;nbsp; set sashelp.vtable (where=(libname="WORK" and memname="LIST_OF_FILES" and NOBS &amp;gt; 0));
&amp;nbsp; call execute("%include '&amp;amp;pname.file-inventories-&amp;amp;databasetype..Part2.sas';");
run;&lt;/PRE&gt;
&lt;P&gt;So the call execute only executes if there is an observation from the set and this only happens if the dataset list_of_files is in work and has observations. &amp;nbsp;However I do still think you should look at the logic of the process and attempt to re-work it.&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;</description>
      <pubDate>Thu, 10 Mar 2016 09:31:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255744#M309876</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-10T09:31:17Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally execute a macro based on proc sql into var?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255835#M309877</link>
      <description>&lt;P&gt;"Out of interest, why? "&lt;/P&gt;
&lt;P&gt;I am not sure if you are asking why I am using a proc SQL + into var, or why am I conditionally executing code, if the later when my program that starts way back with a search and find all zip files on an entire file large system and copy them to a new subdirectory tree bla bla bla...&amp;nbsp;&amp;nbsp; the short of it is, if my program finds a data type that SAS can scan at the metadata level then I want to do it, else skip that file type becasue reading a none existing file even once for metadata bombs out SAS and it will not auto read the reast of my files.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;/U&gt;Sorry if that is not what you were looking for, if why proc SQL verse data step I am more familiar with proc SQL than data steps is the only reason.&amp;nbsp; -KJ&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2016 16:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255835#M309877</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2016-03-10T16:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally execute a macro based on proc sql into var?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255839#M309878</link>
      <description>&lt;P&gt;thanks for the data step example.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2016 16:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/255839#M309878</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2016-03-10T16:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally execute a macro based on proc sql into var?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/256043#M309879</link>
      <description>&lt;P&gt;Yes, sorry, quite general, I mean of course why conditionally execute the code. &amp;nbsp;The reason is that a bit of re-qorking you can avoid all of that. &amp;nbsp;For example you want to run a macro when there appears in a directory a file with _abc_:&lt;/P&gt;
&lt;PRE&gt;filename tmp pipe 'dir "&amp;lt;your_directory&amp;gt;\*.zip" /b';
data _null_;
  infile tmp;
  length buffer $200;
  input buffer $;
  if index(upcase(buffer),"_ABC_") &amp;gt; 0 then 
    call execute(cat('%your_macro(f=',strip(buffer),');'));
run;&lt;/PRE&gt;
&lt;P&gt;The above code reads in the directory listing from the path (/b for only filenames), and if the substr _ABC_ is found in the filename, then a call is put out for the macro to execute with the filename. &amp;nbsp;If no files have the substring, then the datastep finishes having executed all code. &amp;nbsp;It just seems a simpler processing than checking each time, and running some bits.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 09:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-execute-a-macro-based-on-proc-sql-into-var/m-p/256043#M309879</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-11T09:34:54Z</dc:date>
    </item>
  </channel>
</rss>

