<?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: %DO, Iterative Statement in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/DO-Iterative-Statement/m-p/668937#M79169</link>
    <description>&lt;P&gt;You need to use period to let macro processor know where you macro variable name ends.&lt;/P&gt;
&lt;P&gt;But if you had put the numeric suffix at the END of the name instead of trying to embed it in the middle it wouldn't have mattered.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;merge_temp_&amp;amp;i&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Plus then you can use a range of dataset names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set merge_temp_2017 - merge_temp_&amp;amp;years ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 13 Jul 2020 19:19:47 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-07-13T19:19:47Z</dc:date>
    <item>
      <title>%DO, Iterative Statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DO-Iterative-Statement/m-p/668906#M79162</link>
      <description>&lt;P&gt;Hello, below is a sample of the code I'm trying to run; however, I keep getting errors messages: "Apparent symbolic reference I_TEMP not resolved" and about the &amp;amp; symbol not being recognized and thus being ignored. Any ideas what is going on here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro create(years);
	%do i=2017 %to &amp;amp;years;

		/*Comment.*/
		data merge_&amp;amp;i_temp;
		 	set annual.data_ab_&amp;amp;i;
		  	keep year state state_code;
		  	year = &amp;amp;i;
		  	if stcode = "01" then state = "AL" ;
			if stcode = "02" then state = "AK" ;
	
		  	length state_code $43;

		  	array array var1 var2 var3;

		  	do a=1 to 3;
			  	state_code = array[a];
				output;
		  	end;

		 run;
	 
		 /*Comment.*/
		 data merge_&amp;amp;i_temp;
		 	set merge_&amp;amp;i_temp;
			if state_code NE " ";
		 run;

		/*More data and proc steps.*/

	%end;

%mend create;

%create(2019)
&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jul 2020 18:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DO-Iterative-Statement/m-p/668906#M79162</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2020-07-13T18:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: %DO, Iterative Statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DO-Iterative-Statement/m-p/668916#M79165</link>
      <description>&lt;P&gt;The macro processor is looking for the macro variable %i_temp, which likely does not exist. You need to separate the macro variable &amp;amp;i from the rest of the text by using a period.&lt;BR /&gt;Instead of this:&lt;/P&gt;
&lt;PRE&gt;merge_&amp;amp;i_temp;&lt;/PRE&gt;
&lt;P&gt;You should have this:&lt;/P&gt;
&lt;PRE&gt;merge_&amp;amp;i._temp;&lt;/PRE&gt;
&lt;P&gt;You'll need to replace all instances of &amp;amp;i with &amp;amp;i.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jul 2020 18:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DO-Iterative-Statement/m-p/668916#M79165</guid>
      <dc:creator>ketpt42</dc:creator>
      <dc:date>2020-07-13T18:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: %DO, Iterative Statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DO-Iterative-Statement/m-p/668917#M79166</link>
      <description>&lt;P&gt;The idea presented in your earlier thread,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/326526"&gt;@raivester&lt;/a&gt;&amp;nbsp;, is to not use data sets by year, and then you don't need macros, and then you don't run into macro errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could combine all of the annual data sets into one large data set covering multiple years, and all of these coding difficulties caused by macros are gone.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jul 2020 18:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DO-Iterative-Statement/m-p/668917#M79166</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-13T18:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: %DO, Iterative Statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DO-Iterative-Statement/m-p/668930#M79167</link>
      <description>Your second data step is unnecessary.</description>
      <pubDate>Mon, 13 Jul 2020 19:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DO-Iterative-Statement/m-p/668930#M79167</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-13T19:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: %DO, Iterative Statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DO-Iterative-Statement/m-p/668935#M79168</link>
      <description>Thank you! This was exactly what I needed. Originally I named the data set merge_&amp;amp;i and not merge_&amp;amp;i_temp. Apparently not having the period did not matter in the first case since &amp;amp;i ended the data set name.</description>
      <pubDate>Mon, 13 Jul 2020 19:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DO-Iterative-Statement/m-p/668935#M79168</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2020-07-13T19:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: %DO, Iterative Statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DO-Iterative-Statement/m-p/668937#M79169</link>
      <description>&lt;P&gt;You need to use period to let macro processor know where you macro variable name ends.&lt;/P&gt;
&lt;P&gt;But if you had put the numeric suffix at the END of the name instead of trying to embed it in the middle it wouldn't have mattered.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;merge_temp_&amp;amp;i&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Plus then you can use a range of dataset names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set merge_temp_2017 - merge_temp_&amp;amp;years ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jul 2020 19:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DO-Iterative-Statement/m-p/668937#M79169</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-13T19:19:47Z</dc:date>
    </item>
  </channel>
</rss>

