<?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: Create a macro variable with condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-condition/m-p/758724#M239626</link>
    <description>&lt;P&gt;What is wrong with my code?&lt;/P&gt;</description>
    <pubDate>Mon, 02 Aug 2021 07:47:54 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-08-02T07:47:54Z</dc:date>
    <item>
      <title>Create a macro variable with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-condition/m-p/758710#M239614</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to create a macro variable called FromDate that will get the following value:&lt;/P&gt;
&lt;P&gt;IF data set ttt exists then it will get value of max(BirthDate)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF&amp;nbsp;data set ttt doesn't exist then it will get value&amp;nbsp;22158 (Which represent 31Aug2020)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code below is not working well, since data set ttt exists I expect to get value&amp;nbsp;22428 but I get value 22158.&lt;/P&gt;
&lt;P&gt;Why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data ttt;
input BirthDate : date9.;
cards;
15Aug2020'd
28MAY2021'd
;
Run;

%macro RRR;
%if %sysfunc(exist(ttt)) %then %do;
PROC SQL noprint;
select  max(BirthDate) into : FromDate	   
from  ttt
;
QUIT;
%end;
%else %do;
data _null_;
call symputx('FromDate','22158');
run;
%end;
%mend RRR;
%put &amp;amp;FromDate;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;x&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 07:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-condition/m-p/758710#M239614</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-08-02T07:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-condition/m-p/758715#M239618</link>
      <description>&lt;P&gt;untested&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro narf;
  %global FromDate;
  %if %sysfunc(exist(work.ttt)) %then %do;
    proc sql noprint;
      select max(BirthDate) into :FromDate trimmed
        from work.ttt;
    quit;
  %end;
  %else %do;
    %let FromDate = '31Aug2020'd;
  %end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Aug 2021 07:09:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-condition/m-p/758715#M239618</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-02T07:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-condition/m-p/758720#M239623</link>
      <description>&lt;P&gt;Where is this macro variable to be used?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may run into scope issues of where this is defined not being available to where actually wanted.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 07:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-condition/m-p/758720#M239623</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-02T07:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-condition/m-p/758724#M239626</link>
      <description>&lt;P&gt;What is wrong with my code?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 07:47:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-condition/m-p/758724#M239626</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-08-02T07:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-condition/m-p/758729#M239630</link>
      <description>Three places to begin...&lt;BR /&gt;Does your program actually call the macro?  I would expect to see this statement:  %rrr &lt;BR /&gt;Second, for testing purposes, simplify the macro down to a one line version.  After creating ttt:&lt;BR /&gt;%macro rrr2;&lt;BR /&gt;%put %sysfunc(exist(ttt));&lt;BR /&gt;%mend rrr2;&lt;BR /&gt;%rrr2&lt;BR /&gt;Third, is your post showing the actual definition of %rrr or a simplified version?  We need to see the actual first line (%macro %rrr statement).</description>
      <pubDate>Mon, 02 Aug 2021 08:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-with-condition/m-p/758729#M239630</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-08-02T08:11:25Z</dc:date>
    </item>
  </channel>
</rss>

