<?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: sas do loop macro in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-do-loop-macro/m-p/823641#M41108</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MAPPING;
set wanted;
if EngineSize=2 and horsepower=&amp;amp;horsepower;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: This is not a macro command, this is a plain old data set IF statement, not a macro %IF&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But even simpler is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MAPPING;
set wanted;
where horsepower=&amp;amp;horsepower;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and this works because previously you have limited the observations in WANTED to be only those where EngineSize=2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But to continue to simplify ... why do you need two DATA steps for this? One DATA step will do&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wanted;
    set SASHELP.CARS;
    where EngineSize=&amp;amp;size and horsepower=&amp;amp;horsepower ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But even that much isn't always necessary, you can do things like this:&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;proc whatever data=sashelp.cars(where=(enginesize=&amp;amp;size and horsepower=&amp;amp;horsepower));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ADVICE: Always — that's ALWAYS — write working code without macros and without macro variables first. Then converting to code with macros and macro variables is always simpler. If your code does not work without macros and without macro variables, it will NEVER work with macros and with macro variables.&lt;/P&gt;</description>
    <pubDate>Sat, 16 Jul 2022 15:26:03 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-07-16T15:26:03Z</dc:date>
    <item>
      <title>sas do loop macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-do-loop-macro/m-p/823634#M41105</link>
      <description>&lt;P&gt;I have this Query&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;%let size=2;
%let Horsepower=132;
Data wanted;
    Set SASHELP.CARS;
	where EngineSize =&amp;amp;size  ;
Run;
data MAPPING;
set wanted;
 %if  EngineSize =2 %then %do;
        where Horsepower= &amp;amp;Horsepower
        %end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;i want if only&amp;nbsp;&lt;CODE class="  language-sas"&gt;EngineSize&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;read&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;where&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Horsepower&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="token macro-variable"&gt;&amp;amp;Horsepower&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;otherwise no&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jul 2022 13:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-do-loop-macro/m-p/823634#M41105</guid>
      <dc:creator>Daily1</dc:creator>
      <dc:date>2022-07-16T13:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: sas do loop macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-do-loop-macro/m-p/823641#M41108</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MAPPING;
set wanted;
if EngineSize=2 and horsepower=&amp;amp;horsepower;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: This is not a macro command, this is a plain old data set IF statement, not a macro %IF&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But even simpler is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MAPPING;
set wanted;
where horsepower=&amp;amp;horsepower;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and this works because previously you have limited the observations in WANTED to be only those where EngineSize=2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But to continue to simplify ... why do you need two DATA steps for this? One DATA step will do&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wanted;
    set SASHELP.CARS;
    where EngineSize=&amp;amp;size and horsepower=&amp;amp;horsepower ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But even that much isn't always necessary, you can do things like this:&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;proc whatever data=sashelp.cars(where=(enginesize=&amp;amp;size and horsepower=&amp;amp;horsepower));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ADVICE: Always — that's ALWAYS — write working code without macros and without macro variables first. Then converting to code with macros and macro variables is always simpler. If your code does not work without macros and without macro variables, it will NEVER work with macros and with macro variables.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jul 2022 15:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-do-loop-macro/m-p/823641#M41108</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-16T15:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: sas do loop macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-do-loop-macro/m-p/823651#M41109</link>
      <description>&lt;P&gt;Can you provide a description of what you are trying to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This statement makes no sense.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %if  EngineSize =2 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because it can never be true.&amp;nbsp; The digit 2 is never equal to a string that starts with an upper case E.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you wanted to test if the macro variable SIZE was 2 you could have done.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MAPPING;
  set wanted;
%if &amp;amp;size=2 %then %do;
  where Horsepower= &amp;amp;Horsepower;
%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you wanted to test if the value of the variable named ENGINESIZE is 2 then you will need to use SAS code and not MACRO code.&amp;nbsp; So perhaps you wanted something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MAPPING;
  set wanted;
  if enginesize=2 then do;
    if Horsepower= &amp;amp;Horsepower;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that are WHERE statement cannot execute conditionally so had to switch to a subsetting IF statement instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jul 2022 18:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-do-loop-macro/m-p/823651#M41109</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-16T18:26:49Z</dc:date>
    </item>
  </channel>
</rss>

