<?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 Conditional executions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-executions/m-p/813905#M321268</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Let's say that the following situation :&lt;/P&gt;
&lt;P&gt;User define 2 macro variables : business&amp;nbsp; and&amp;nbsp;private&amp;nbsp; (using %let statement ).&lt;/P&gt;
&lt;P&gt;I want to create conditions as following:&lt;/P&gt;
&lt;P&gt;If macro variable&amp;nbsp;business&amp;gt;=1 then need to do some actions (see the code below).....&lt;/P&gt;
&lt;P&gt;If macro variable&amp;nbsp;private&amp;gt;=1 then need to do some actions (see the code below).....&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;Is there is another way or just the way I wrote?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let business=2;
%let private=0;

%macro RRR;
%IF &amp;amp;business.&amp;gt;=1 %then %do;
proc sql;
create table tbl1 as
select make,
       sum(invoice) as  invoice
from  sashelp.cars
where type='Sports'
group by make
;
quit;

proc sql;
create table class_M as
select *
from sashelp.class
where sex='M'
;
quit;
%End;


%IF &amp;amp;private.&amp;gt;=1 %then %do;
proc sql;
create table class_F as
select *
from sashelp.class
where sex='F' and weight&amp;gt;=80
;
quit;

proc sql;
create table class_age_le12 as
select *
from sashelp.class
where age&amp;lt;=12
;
quit;
%End;
%mend RRR;
%RRR;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 May 2022 19:03:33 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2022-05-17T19:03:33Z</dc:date>
    <item>
      <title>Conditional executions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-executions/m-p/813905#M321268</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Let's say that the following situation :&lt;/P&gt;
&lt;P&gt;User define 2 macro variables : business&amp;nbsp; and&amp;nbsp;private&amp;nbsp; (using %let statement ).&lt;/P&gt;
&lt;P&gt;I want to create conditions as following:&lt;/P&gt;
&lt;P&gt;If macro variable&amp;nbsp;business&amp;gt;=1 then need to do some actions (see the code below).....&lt;/P&gt;
&lt;P&gt;If macro variable&amp;nbsp;private&amp;gt;=1 then need to do some actions (see the code below).....&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;Is there is another way or just the way I wrote?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let business=2;
%let private=0;

%macro RRR;
%IF &amp;amp;business.&amp;gt;=1 %then %do;
proc sql;
create table tbl1 as
select make,
       sum(invoice) as  invoice
from  sashelp.cars
where type='Sports'
group by make
;
quit;

proc sql;
create table class_M as
select *
from sashelp.class
where sex='M'
;
quit;
%End;


%IF &amp;amp;private.&amp;gt;=1 %then %do;
proc sql;
create table class_F as
select *
from sashelp.class
where sex='F' and weight&amp;gt;=80
;
quit;

proc sql;
create table class_age_le12 as
select *
from sashelp.class
where age&amp;lt;=12
;
quit;
%End;
%mend RRR;
%RRR;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 19:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-executions/m-p/813905#M321268</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-05-17T19:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional executions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-executions/m-p/813910#M321269</link>
      <description>&lt;P&gt;The first line under %MACRO RRR;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF &amp;amp;business&amp;gt;=1 then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;IF statements can only be in a DATA step. This is not in a DATA step and won't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, this does not have to be in a DATA step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;business&amp;gt;=1 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and it needs to end with &lt;FONT face="courier new,courier"&gt;%END&lt;/FONT&gt;; and not &lt;FONT face="courier new,courier"&gt;END;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you need to change this throughout your code.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 19:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-executions/m-p/813910#M321269</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-17T19:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional executions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-executions/m-p/813919#M321270</link>
      <description>&lt;P&gt;If you are running a current version of SAS you can have the simple %IF/%THEN/%DO/%END blocks you have in open code without the need to define and call a macro.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 19:11:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-executions/m-p/813919#M321270</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-17T19:11:49Z</dc:date>
    </item>
  </channel>
</rss>

