<?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: Running a macro from _N_=1 to end of file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-from-N-1-to-end-of-file/m-p/433310#M107407</link>
    <description>&lt;P&gt;oh, I got it. Not perfect but get the job done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a quick question: why this one doesnt work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want_&amp;amp;entry_name&amp;amp;entry_value; set _entry_temp;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data entry;
input variable $ value;
datalines;
a 1
a 2
b 6
b 9
;run;

proc sql noprint;
select count(*) into: nobs from entry;quit;

%put &amp;amp;nobs;

data masterfile; 
input a b c d;
datalines;
 1 2 3 4
 1 9 3 2
 2 9 2 3
;
run;


%MACRO SINGLE_FACTOR;
%DO ENTRY_COUNT=1 %TO &amp;amp;NOBS;
%PUT "NEW ROUND";
%put &amp;amp;ENTRY_COUNT;
	*the first record in entry file;
	data _entry_temp; set entry;
	if _N_=&amp;amp;ENTRY_COUNT;
	run;

	*create macro value to feed the inner macro;
	proc sql noprint;	select variable into:   entry_name 		from _entry_temp; quit;
	proc sql noprint;	select value into 	: 	entry_value 	from _entry_temp; quit;

	%put &amp;amp;entry_name;run; 
	%put &amp;amp;entry_value;run; 

	*Use the above to 2 value to feed inner Macro in a seperate file
		for checking purpose, I just want to create new file with macro name;
			data want; set masterfile;
			IF &amp;amp;entry_name=&amp;amp;entry_value;
			run;

%END;
%MEND;

%SINGLE_FACTOR;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 01 Feb 2018 22:33:00 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2018-02-01T22:33:00Z</dc:date>
    <item>
      <title>Running a macro from _N_=1 to end of file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-from-N-1-to-end-of-file/m-p/433303#M107404</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I have 2 files: entry&amp;nbsp;file and Master file.&lt;/P&gt;
&lt;P&gt;I want to take subsample from Master file that meet each condition in&amp;nbsp;entry file to further analyze.&lt;/P&gt;
&lt;P&gt;(it is a bit like proc SQL to get subsample but the analysis is complicate that I can create that big file using proc SQL).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So my solution is that:&lt;/P&gt;
&lt;P&gt;Step &lt;STRONG&gt;1&lt;/STRONG&gt;: start from entry file, work with the 1st record, &lt;FONT color="#FF0000"&gt;a&lt;/FONT&gt; and &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Step &lt;STRONG&gt;2&lt;/STRONG&gt;: I go to mater file and select all records that meet condition in step &lt;STRONG&gt;1&lt;/STRONG&gt;, or records with &lt;FONT color="#FF0000"&gt;a&lt;/FONT&gt; =&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt; --&amp;gt; &lt;STRONG&gt;2&lt;/STRONG&gt; record&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; analyze that subsample.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; after I am done&lt;/P&gt;
&lt;P&gt;Go back to step &lt;STRONG&gt;1&lt;/STRONG&gt;: work on &lt;STRONG&gt;2&lt;/STRONG&gt;nd record&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I vision my code has &lt;STRONG&gt;2&lt;/STRONG&gt; macro;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Outer macro that run throught entry file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Inner macro that pick record from master and process&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to run from the beginning to the end of the entry file but I dont know how to do&lt;/P&gt;
&lt;P&gt;it.&lt;/P&gt;
&lt;P&gt;Could you please help me?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for your help.&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;
data entry;
input variable $ value;
datalines;
a 1
a 2
b 6
b 9
;run;

data masterfile; 
input a b c d;
datalines;
 1 2 3 4
 1 9 3 2
 2 9 2 3
;
run;


	*the first record in entry file;
	data _entry_temp; set entry;
	if _N_=1;
	run;

	*create macro value to feed the inner macro;
	proc sql noprint;	select variable into:   entry_name 	from _entry_temp; quit;
	proc sql noprint;	select value into : 	entry_value 	from _entry_temp; quit;

	*Use the above to 2 value to feed inner Macro in a seperate file
	for checking purpose, I just want to create new file with macro name;
		%macro inner(entry_name2 = ,entry_value2=);
			data want_&amp;amp;entry_name.&amp;amp;entry_value; set _entry_temp;
			run;
		%mend;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 22:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-from-N-1-to-end-of-file/m-p/433303#M107404</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-02-01T22:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: Running a macro from _N_=1 to end of file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-from-N-1-to-end-of-file/m-p/433310#M107407</link>
      <description>&lt;P&gt;oh, I got it. Not perfect but get the job done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a quick question: why this one doesnt work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want_&amp;amp;entry_name&amp;amp;entry_value; set _entry_temp;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data entry;
input variable $ value;
datalines;
a 1
a 2
b 6
b 9
;run;

proc sql noprint;
select count(*) into: nobs from entry;quit;

%put &amp;amp;nobs;

data masterfile; 
input a b c d;
datalines;
 1 2 3 4
 1 9 3 2
 2 9 2 3
;
run;


%MACRO SINGLE_FACTOR;
%DO ENTRY_COUNT=1 %TO &amp;amp;NOBS;
%PUT "NEW ROUND";
%put &amp;amp;ENTRY_COUNT;
	*the first record in entry file;
	data _entry_temp; set entry;
	if _N_=&amp;amp;ENTRY_COUNT;
	run;

	*create macro value to feed the inner macro;
	proc sql noprint;	select variable into:   entry_name 		from _entry_temp; quit;
	proc sql noprint;	select value into 	: 	entry_value 	from _entry_temp; quit;

	%put &amp;amp;entry_name;run; 
	%put &amp;amp;entry_value;run; 

	*Use the above to 2 value to feed inner Macro in a seperate file
		for checking purpose, I just want to create new file with macro name;
			data want; set masterfile;
			IF &amp;amp;entry_name=&amp;amp;entry_value;
			run;

%END;
%MEND;

%SINGLE_FACTOR;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 22:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-from-N-1-to-end-of-file/m-p/433310#M107407</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-02-01T22:33:00Z</dc:date>
    </item>
  </channel>
</rss>

