<?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: Execute Part of the Code with Macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956441#M42973</link>
    <description>&lt;P&gt;You can use %IF blocks for that.&lt;/P&gt;
&lt;P&gt;And if you keep them very simple you don't even need to define a macro.&lt;/P&gt;
&lt;P&gt;Instead just set a macro VARIABLE and have the %IF logic test that macro variables value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's make a simpler/clearer example.&amp;nbsp; Say you want to create either the MALE or the FEMALE dummy variable you could do something like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First decide how to parameterize you macro variable.&amp;nbsp; For example you might decide it is named GENDER and should have a value of MALE or FEMALE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let gender=MALE;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then at the point in your code where you make the dummy variable add the %IF logic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data with_dummy;
  set have;
%if %upcase(&amp;amp;gender)=MALE %then %do;
  &amp;amp;gender = (sex=1) ;
%end;
%if %upcase(&amp;amp;gender)=FEMALE %then %do;
  &amp;amp;gender = (sex=2);
%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 17 Jan 2025 17:06:39 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-01-17T17:06:39Z</dc:date>
    <item>
      <title>Execute Part of the Code with Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956382#M42964</link>
      <description>&lt;P&gt;How can I execute part of the code without commenting out code? Let's say I have the following code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset_1;
set dataset_1;
male=0;
if sex=1 then male=1;
run;

data dataset_2;
set dataset_2;
female=0;
if sex=2 then female=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would like to execute only the first data step without commenting out the second data step. It would great if I could have a macro at the very top of the script and if this macro equals to 1 the script would execute on the first data step and if the macro equals to 2 then it would execute both data steps. Is this possible?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2025 02:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956382#M42964</guid>
      <dc:creator>trevand</dc:creator>
      <dc:date>2025-01-17T02:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Part of the Code with Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956384#M42965</link>
      <description>&lt;P&gt;That's what %if / %then / %else logic is for:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro runit(n);
    %if &amp;amp;n=1 %then %do;
        * do n=1 stuff ;
    %end;
    %else %if &amp;amp;n=2 %then %do;
        * do n=2 stuff ;
    %end;
%mend; *runit();

%runit(1)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jan 2025 03:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956384#M42965</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-01-17T03:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Part of the Code with Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956390#M42966</link>
      <description>&lt;P&gt;I am tempted to ask why you are creating the variables male/female at all, but this maybe out of scope.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2025 07:01:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956390#M42966</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2025-01-17T07:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Part of the Code with Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956435#M42970</link>
      <description>&lt;P&gt;I don't. It was just an example with some easy code. I usually have only one dummy either female or male.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2025 16:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956435#M42970</guid>
      <dc:creator>trevand</dc:creator>
      <dc:date>2025-01-17T16:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Part of the Code with Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956438#M42971</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223320"&gt;@quickbluefish&lt;/a&gt; how would you adjust your code to either execute only first block or both blocks. Right now it does either first or second block if I understand the code correctly. &lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2025 16:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956438#M42971</guid>
      <dc:creator>trevand</dc:creator>
      <dc:date>2025-01-17T16:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Part of the Code with Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956440#M42972</link>
      <description>&lt;P&gt;That's just because of the %else part.&amp;nbsp; You could, for example, do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro runit(run1=0, run2=0);
    %if &amp;amp;run1 %then %do;
        * do run1 stuff ;
    %end;
    %if &amp;amp;run2 %then %do;
        * do run2 stuff ;
    %end;
%mend; *runit();

%runit(run1=1, run2=1);  * run both ;
%runit(run1=0, run2=1);  * run only the 2nd... ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jan 2025 16:55:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956440#M42972</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-01-17T16:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Part of the Code with Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956441#M42973</link>
      <description>&lt;P&gt;You can use %IF blocks for that.&lt;/P&gt;
&lt;P&gt;And if you keep them very simple you don't even need to define a macro.&lt;/P&gt;
&lt;P&gt;Instead just set a macro VARIABLE and have the %IF logic test that macro variables value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's make a simpler/clearer example.&amp;nbsp; Say you want to create either the MALE or the FEMALE dummy variable you could do something like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First decide how to parameterize you macro variable.&amp;nbsp; For example you might decide it is named GENDER and should have a value of MALE or FEMALE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let gender=MALE;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then at the point in your code where you make the dummy variable add the %IF logic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data with_dummy;
  set have;
%if %upcase(&amp;amp;gender)=MALE %then %do;
  &amp;amp;gender = (sex=1) ;
%end;
%if %upcase(&amp;amp;gender)=FEMALE %then %do;
  &amp;amp;gender = (sex=2);
%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jan 2025 17:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-Part-of-the-Code-with-Macro/m-p/956441#M42973</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-17T17:06:39Z</dc:date>
    </item>
  </channel>
</rss>

