<?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 Create new file using macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-file-using-macro/m-p/545410#M150876</link>
    <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;After a long process, my program generate an Error_file.&lt;/P&gt;
&lt;P&gt;What I want is that: If there is No record in Error_file, give notice "No Error". If there is record, give notice "Having ERROR".&lt;/P&gt;
&lt;P&gt;This notice will be created in a SAS file name NOTE1 and will export to Excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I try the code below but somehow it doesn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please help me?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;KEY:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Most SAS data steps stop when SAS reads past the end of the input (either the SET/MERGE/UPDATE statement or the INPUT statement).&amp;nbsp; So if you want to do something when there are no observations on the input do it&lt;U&gt; BEFORE the SET statement.&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data error_file;
input var;
datalines;
1
2
;

	proc sql noprint;	
	select count(*) into : N_no_project_code from error;
	quit;
	%put &amp;amp;N_no_project_code;


	data note1; set _NULL_;		
	%macro ex();
	data note1; 
	if eof then do;	
		%if &amp;amp;N_no_project_code=0 %then %do;	topic="Project code: no problem";		%end;
		%else %do;topic="Project code: MISSING CODE!!! "; %end;
	output;
	end;

	&lt;STRONG&gt;SET&lt;/STRONG&gt; note1 end=eof;
	run;
	%mend;
	%ex();
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data error;
input var;
datalines;
1
2
;

	proc sql noprint;	
	select count(*) into : N_no_project_code from error;
	quit;
	%put &amp;amp;N_no_project_code;


	data note1; set _NULL_;		
	%macro ex();
	data note1; set note1 end=eof;
	output;
	if eof then do;	
		%if &amp;amp;N_no_project_code=0 %then %do;	topic="NO ERROR";		%end;
		%else %do;topic="HAVING ERROR!!! "; %end;
	output;
	end;
	run;
	%mend;
	%ex();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 23 Mar 2019 03:44:44 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2019-03-23T03:44:44Z</dc:date>
    <item>
      <title>Create new file using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-file-using-macro/m-p/545410#M150876</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;After a long process, my program generate an Error_file.&lt;/P&gt;
&lt;P&gt;What I want is that: If there is No record in Error_file, give notice "No Error". If there is record, give notice "Having ERROR".&lt;/P&gt;
&lt;P&gt;This notice will be created in a SAS file name NOTE1 and will export to Excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I try the code below but somehow it doesn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please help me?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;KEY:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Most SAS data steps stop when SAS reads past the end of the input (either the SET/MERGE/UPDATE statement or the INPUT statement).&amp;nbsp; So if you want to do something when there are no observations on the input do it&lt;U&gt; BEFORE the SET statement.&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data error_file;
input var;
datalines;
1
2
;

	proc sql noprint;	
	select count(*) into : N_no_project_code from error;
	quit;
	%put &amp;amp;N_no_project_code;


	data note1; set _NULL_;		
	%macro ex();
	data note1; 
	if eof then do;	
		%if &amp;amp;N_no_project_code=0 %then %do;	topic="Project code: no problem";		%end;
		%else %do;topic="Project code: MISSING CODE!!! "; %end;
	output;
	end;

	&lt;STRONG&gt;SET&lt;/STRONG&gt; note1 end=eof;
	run;
	%mend;
	%ex();
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data error;
input var;
datalines;
1
2
;

	proc sql noprint;	
	select count(*) into : N_no_project_code from error;
	quit;
	%put &amp;amp;N_no_project_code;


	data note1; set _NULL_;		
	%macro ex();
	data note1; set note1 end=eof;
	output;
	if eof then do;	
		%if &amp;amp;N_no_project_code=0 %then %do;	topic="NO ERROR";		%end;
		%else %do;topic="HAVING ERROR!!! "; %end;
	output;
	end;
	run;
	%mend;
	%ex();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 03:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-file-using-macro/m-p/545410#M150876</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-03-23T03:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create new file using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-file-using-macro/m-p/545413#M150877</link>
      <description>&lt;P&gt;When you say it doesn't work, what do you mean?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you get an error?&amp;nbsp; (I wouldn't think so, from looking at the code, it looks like it should run successfully).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you getting surprising results?&amp;nbsp; If so, what is the unexpected result you are getting?&amp;nbsp; Can you post the log from running this section of the code?&amp;nbsp; Are you sure that when your program runs without errors, work.no_project_check will be created and will have 0 observations?&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 02:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-file-using-macro/m-p/545413#M150877</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-03-23T02:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create new file using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-file-using-macro/m-p/545417#M150878</link>
      <description>&lt;P&gt;The macro doesn't create anything.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 03:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-file-using-macro/m-p/545417#M150878</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-03-23T03:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create new file using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-file-using-macro/m-p/545418#M150879</link>
      <description>&lt;P&gt;There a logical error there and a programming style error.&lt;/P&gt;
&lt;P&gt;For the style error, don't define a macro in the middle of a data step. Define the macro at the top of the program and then call it where you want it to run.&amp;nbsp; You are just confusing yourself by mixing the definition of a macro into the code for a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the logic error:&lt;/P&gt;
&lt;P&gt;Most SAS data steps stop when SAS reads past the end of the input (either the SET/MERGE/UPDATE statement or the INPUT statement).&amp;nbsp; So if you want to do something when there are no observations on the input do it BEFORE the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's ignore your code and look at your problem description.&amp;nbsp; You have an existing dataset named&amp;nbsp;&lt;SPAN&gt;ERROR_FILE.&amp;nbsp; You want to make a new dataset named NOTE1 that will have a character variable indicating if there were any problems.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So if you just want to test if there are any records in the file use the NOBS= option on the SET statement to count for you.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data note1;
  length topic $100 ;
  if nobs then topic=catx(' ','Found',put(nobs,comma32.),'errors.');
  else topic='No errors';
  stop;
  set error_file (drop=_all_) nobs=nobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 03:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-file-using-macro/m-p/545418#M150879</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-23T03:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Create new file using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-file-using-macro/m-p/545422#M150882</link>
      <description>&lt;P&gt;Yes, Tom.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I move the SET to the end and it works!&lt;/P&gt;
&lt;P&gt;Thanks a lot.&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data error_file;
input var;
datalines;
1
2
;

	proc sql noprint;	
	select count(*) into : N_no_project_code from error;
	quit;
	%put &amp;amp;N_no_project_code;


	data note1; set _NULL_;		
	%macro ex();
	data note1; 
	if eof then do;	
		%if &amp;amp;N_no_project_code=0 %then %do;	topic="Project code: no problem";		%end;
		%else %do;topic="Project code: MISSING CODE!!! "; %end;
	output;
	end;

	set note1 end=eof;
	run;
	%mend;
	%ex();
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Mar 2019 03:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-file-using-macro/m-p/545422#M150882</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-03-23T03:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create new file using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-file-using-macro/m-p/545423#M150883</link>
      <description>Please post your log from running the sql step and then running the macro.&lt;BR /&gt;</description>
      <pubDate>Sat, 23 Mar 2019 03:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-file-using-macro/m-p/545423#M150883</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-03-23T03:44:22Z</dc:date>
    </item>
  </channel>
</rss>

