<?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: Skip Marco iteration if datafile less than certain records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432774#M107223</link>
    <description>&lt;P&gt;Corrections to your macro: Hope it helps.&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;%Macro running_over_all_data(var_name = , value=);
	
	data _TEMP; set original_file;
	keep date tradetim	;
	     IF &amp;amp;var_name=&amp;amp;value;
	run;                                                *Not Touching your Data step;
	
			*if too small number of record --&amp;gt; no running code;
			Proc Sql noprint;
                        select count(*) into :NOBS from _TEMPl;
                        Quit;                *Taking count of the whole table;

	%IF &amp;amp;NOBS &amp;gt; 5 %THEN %DO;
	        %include "C:\Users\Main analysis code.sas" /lrecl=50000;
	%END;
%Mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 31 Jan 2018 14:58:58 GMT</pubDate>
    <dc:creator>Satish_Parida</dc:creator>
    <dc:date>2018-01-31T14:58:58Z</dc:date>
    <item>
      <title>Skip macro iteration if data file less than certain records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432716#M107200</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In each iteration, my macro will create a new file and run the analysis.&lt;/P&gt;
&lt;P&gt;However, I dont want to run the analysis for a new file with less than 20 records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please fix my code below?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro running_over_all_data(var_name = , value=);
	
	data _TEMP; set original_file;
	keep date tradetim	;
	     IF &amp;amp;var_name=&amp;amp;value;
	run;
	
			*if too small number of record --&amp;gt; no running code;
			data _NULL_;
				call symput('nobs',put(x,best.));
				set _TEMP nobs=x;
				stop; 
				put nobs;

	%IF &amp;amp;NOBS &amp;gt; 5 %THEN %DO;
	        %include "C:\Users\Main analysis code.sas" /lrecl=50000;
	%END;
%Mend;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jan 2018 16:19:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432716#M107200</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-01-31T16:19:24Z</dc:date>
    </item>
    <item>
      <title>Re: Skip Marco iteration if datafile less than certain records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432724#M107203</link>
      <description>&lt;PRE&gt;data _null_;
  set sashelp.vtable (where=(libname="WORK" and memname="ORIGINAL_FILE" and nobs &amp;gt; 20));
  call execute('%include "c:/users/main analysis code.sas" / lrecl=5000;');
run;&lt;/PRE&gt;
&lt;P&gt;No need for all that code, the set will only create an observation if more than 20 records are present, if there is no observation then the call execute does not get generated.&amp;nbsp; Simple.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 13:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432724#M107203</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-31T13:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Skip Marco iteration if datafile less than certain records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432729#M107207</link>
      <description>&lt;P&gt;In my case, I might have to SQL inside Macro to get the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 13:59:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432729#M107207</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-01-31T13:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: Skip Marco iteration if datafile less than certain records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432731#M107208</link>
      <description>&lt;P&gt;Your DATA _NULL_ step needs a RUN statement.&amp;nbsp; Without it, macro language examines &amp;amp;NOBS before executing the DATA step.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 14:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432731#M107208</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-31T14:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Skip Marco iteration if datafile less than certain records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432732#M107209</link>
      <description>&lt;P&gt;You can put any code you like before this, SQL, SAS anything.&amp;nbsp; I don't see what that has to do with the question you asked?&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 14:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432732#M107209</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-31T14:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: Skip Marco iteration if datafile less than certain records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432744#M107216</link>
      <description>&lt;P&gt;Since your data step has not yet run when the %if condition is evaluated (it will start to run once a step boundary is detected, which happens at the first proc or data stament in the included file), &amp;amp;nobs does not exist (or it could exist in the global symbol table with a wrong value).&lt;/P&gt;
&lt;P&gt;Add a run statement before your %if.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 14:27:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432744#M107216</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-31T14:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Skip Marco iteration if datafile less than certain records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432759#M107218</link>
      <description>&lt;P&gt;&lt;SPAN class="token macrobound"&gt;%Macro&lt;/SPAN&gt; running_over_all_data&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;var_name &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;value&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&amp;nbsp; _TEMP&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; original_file&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token keyword"&gt;keep&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;date&lt;/SPAN&gt; tradetim &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token keyword"&gt;%IF&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;var_name&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;value&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token comment"&gt;*if too small number of record --&amp;gt; no running code;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; _NULL_&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;%do i=1 %to nobs;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; _TEMP&amp;nbsp;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;%if &amp;amp;i ge 20 then do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token macrostatement"&gt;%include&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"C:\Users\Main analysis code.sas"&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;lrecl&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;50000&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token macrostatement"&gt;%END&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token macrobound"&gt;%Mend&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 14:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432759#M107218</guid>
      <dc:creator>srinath3111</dc:creator>
      <dc:date>2018-01-31T14:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Skip Marco iteration if datafile less than certain records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432765#M107220</link>
      <description>&lt;P&gt;Wow.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;

set _TEMP (where=(_N_&amp;gt;=20) then  Do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you ever get that to run, you're McGyver.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 14:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432765#M107220</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-31T14:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Skip Marco iteration if datafile less than certain records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432774#M107223</link>
      <description>&lt;P&gt;Corrections to your macro: Hope it helps.&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;%Macro running_over_all_data(var_name = , value=);
	
	data _TEMP; set original_file;
	keep date tradetim	;
	     IF &amp;amp;var_name=&amp;amp;value;
	run;                                                *Not Touching your Data step;
	
			*if too small number of record --&amp;gt; no running code;
			Proc Sql noprint;
                        select count(*) into :NOBS from _TEMPl;
                        Quit;                *Taking count of the whole table;

	%IF &amp;amp;NOBS &amp;gt; 5 %THEN %DO;
	        %include "C:\Users\Main analysis code.sas" /lrecl=50000;
	%END;
%Mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jan 2018 14:58:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432774#M107223</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-01-31T14:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Skip Marco iteration if datafile less than certain records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432811#M107238</link>
      <description>&lt;P&gt;Another version - SQL creates the count automatically so that's a change and then if you're running this multiple times you should clean up the _temp data set so the next time you run it you aren't hitting an old data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%Macro running_over_all_data(var_name = , value=);
	
    proc sql;
    create table _temp as
    select date, tradetim
    from original_file
    where &amp;amp;var_name=&amp;amp;value;
    quit;

    %let nobs=&amp;amp;sqlobs;


	%IF &amp;amp;NOBS &amp;gt; 5 %THEN %DO;
	        %include "C:\Users\Main analysis code.sas" /lrecl=50000;
	%END;

    %*always clean up when you Are going to run a macro multiple times;
    proc sql noprint;
    drop table _temp;
    quit;

%Mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jan 2018 16:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432811#M107238</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-31T16:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: Skip Marco iteration if datafile less than certain records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432888#M107264</link>
      <description>&lt;P&gt;WOW that's great.&lt;/P&gt;
&lt;P&gt;Thanks a lot.&lt;/P&gt;
&lt;P&gt;HC&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 19:53:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-macro-iteration-if-data-file-less-than-certain-records/m-p/432888#M107264</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-01-31T19:53:17Z</dc:date>
    </item>
  </channel>
</rss>

