<?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: Macro do loop if then in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-if-then/m-p/594975#M15709</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/148102"&gt;@torvyle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS is running the following code but results are not being generated. I'm running Enterprise Guide 7.12.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro abc;
	data want;
		set have;
		%do num=1 %to 25;
			%if diag_code&amp;amp;num. in ("Z590", "Z591", "Z598") %then
				dcheck&amp;amp;num.=1;
		%end;
	run;
%mend;
%abc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do not use the macro language for manipulating &lt;EM&gt;data&lt;/EM&gt;. Macro language is for manipulating &lt;EM&gt;code&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;Use the data step's tools for this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array diags {*} diag_code1-diag_code25;
array checks {*} dcheck1-dcheck25;
do num = 1 to 25;
  if diags{num} in ("Z590", "Z591", "Z598")
  then checks{num} = 1;
end;
drop num;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 09 Oct 2019 08:34:47 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-10-09T08:34:47Z</dc:date>
    <item>
      <title>Macro do loop if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-if-then/m-p/594896#M15702</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS is running the following code but results are not being generated. I'm running Enterprise Guide 7.12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro abc;
	data want;
		set have;
		%do num=1 %to 25;
			%if diag_code&amp;amp;num. in ("Z590", "Z591", "Z598") %then
				dcheck&amp;amp;num.=1;
		%end;
	run;
%mend;
%abc;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 20:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-if-then/m-p/594896#M15702</guid>
      <dc:creator>torvyle</dc:creator>
      <dc:date>2019-10-08T20:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro do loop if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-if-then/m-p/594899#M15704</link>
      <description>What happens if you use an array instead of macro code here?&lt;BR /&gt;Why are you using macros instead of arrays?</description>
      <pubDate>Tue, 08 Oct 2019 21:13:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-if-then/m-p/594899#M15704</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-08T21:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro do loop if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-if-then/m-p/594900#M15705</link>
      <description>&lt;P&gt;You could switch to arrays, as suggested.&amp;nbsp; Then you wouldn't need any macro language at all.&amp;nbsp; However, you can get macro language to do the job easily enough by cutting out a couple of percent signs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro abc;
	data want;
		set have;
		%do num=1 %to 25;
			if diag_code&amp;amp;num. in ("Z590", "Z591", "Z598") then
				dcheck&amp;amp;num.=1;
		%end;
	run;
%mend;
%abc&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The idea is to have the DATA step process the data.&amp;nbsp; The role of macro language is to make sure that the correct DATA step code gets generated.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 21:19:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-if-then/m-p/594900#M15705</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-10-08T21:19:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro do loop if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-if-then/m-p/594975#M15709</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/148102"&gt;@torvyle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS is running the following code but results are not being generated. I'm running Enterprise Guide 7.12.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro abc;
	data want;
		set have;
		%do num=1 %to 25;
			%if diag_code&amp;amp;num. in ("Z590", "Z591", "Z598") %then
				dcheck&amp;amp;num.=1;
		%end;
	run;
%mend;
%abc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do not use the macro language for manipulating &lt;EM&gt;data&lt;/EM&gt;. Macro language is for manipulating &lt;EM&gt;code&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;Use the data step's tools for this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array diags {*} diag_code1-diag_code25;
array checks {*} dcheck1-dcheck25;
do num = 1 to 25;
  if diags{num} in ("Z590", "Z591", "Z598")
  then checks{num} = 1;
end;
drop num;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Oct 2019 08:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-if-then/m-p/594975#M15709</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-09T08:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro do loop if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-if-then/m-p/595027#M15723</link>
      <description>&lt;P&gt;Thanks, everyone.&amp;nbsp; KurtBremser's solution works too.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2019 12:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-if-then/m-p/595027#M15723</guid>
      <dc:creator>torvyle</dc:creator>
      <dc:date>2019-10-09T12:41:11Z</dc:date>
    </item>
  </channel>
</rss>

