<?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: Define a macro with an if-condition in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/754575#M29972</link>
    <description>I tested your code and it works well. My problem is, that i have the names of the month in german.&lt;BR /&gt;So Mar = Mrz, May = Mai, Oct = Okt, Dec = Dez. Is there a solution for this? Maybe another format?&lt;BR /&gt;</description>
    <pubDate>Fri, 16 Jul 2021 12:27:33 GMT</pubDate>
    <dc:creator>Hansi_12345</dc:creator>
    <dc:date>2021-07-16T12:27:33Z</dc:date>
    <item>
      <title>Define a macro with an if-condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/754571#M29970</link>
      <description>&lt;P&gt;Hi SAS-Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a problem and have no idea how to fix it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to define a macro-variable with an if-condition.&lt;/P&gt;&lt;P&gt;I mean i have e.g. the&amp;nbsp; macro-variable "current_month" that is 3. In the next step i want to convert it into a macro called "month_test" that include the month as a name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried it with the attached code but get the error "Statement is not valid..."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let current_Month = 3;
%let month_test = &amp;amp;test_a;
&lt;BR /&gt;%macro testmonth(Month=);
%if &amp;amp;Month = 1 %then %do;
    &amp;amp;test_a = Jan
%end;
%else %if &amp;amp;Month = 2 %then %do;
    &amp;amp;test_a = Feb
%end;
%else %if &amp;amp;Month = 3 %then %do;
    &amp;amp;test_a = Mar
%end;
%else
  &amp;amp;test_a = Dec;;
run;
%mend testmonth;
%testmonth(Month=&amp;amp;current_Month);&lt;/PRE&gt;&lt;P&gt;I hope u understand what i mean. I would be realy happy, if u could help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 12:11:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/754571#M29970</guid>
      <dc:creator>Hansi_12345</dc:creator>
      <dc:date>2021-07-16T12:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Define a macro with an if-condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/754573#M29971</link>
      <description>&lt;P&gt;Not a direct answer to why your macro code is producing errors ... but ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't use a macro at all here. That's a huge amount of typing, when this will get the job done with much less typing and no macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let current_month=3;
data _null_;
    call symputx('test_a',put(mdy(&amp;amp;current_month,1,2021),monname3.));
run;
%put &amp;amp;=test_a;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Jul 2021 12:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/754573#M29971</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-16T12:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: Define a macro with an if-condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/754575#M29972</link>
      <description>I tested your code and it works well. My problem is, that i have the names of the month in german.&lt;BR /&gt;So Mar = Mrz, May = Mai, Oct = Okt, Dec = Dez. Is there a solution for this? Maybe another format?&lt;BR /&gt;</description>
      <pubDate>Fri, 16 Jul 2021 12:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/754575#M29972</guid>
      <dc:creator>Hansi_12345</dc:creator>
      <dc:date>2021-07-16T12:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Define a macro with an if-condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/754577#M29973</link>
      <description>&lt;P&gt;Google finds the answer quickly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/New-SAS-User/Convert-month-number-into-month-name-in-GERMAN/td-p/693155" target="_blank"&gt;https://communities.sas.com/t5/New-SAS-User/Convert-month-number-into-month-name-in-GERMAN/td-p/693155&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 12:33:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/754577#M29973</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-16T12:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Define a macro with an if-condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/754579#M29974</link>
      <description>&lt;P&gt;Right now it is only generating part of a statement.&amp;nbsp; If you want it to only generate part of statement then you have to call the macro so that the generated code can be using in a statement.&amp;nbsp; For example in a %PUT statement.&lt;/P&gt;
&lt;PRE&gt;386   %put %testmonth(Month=&amp;amp;current_Month);
WARNING: Apparent symbolic reference TEST_A not resolved.
&amp;amp;test_a = Mar
&lt;/PRE&gt;
&lt;P&gt;What code is it that you want the macro to generate?&lt;/P&gt;
&lt;P&gt;What is the macro variable TEST_A that the code is referencing? What types of values will it contain?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is confusing to reference a macro variable in the middle of a macro that is not either an input or local.&amp;nbsp; At a minimum you should add a comment to explain where the macro variable should come from and what types of values it should have.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 12:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/754579#M29974</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-16T12:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: Define a macro with an if-condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/755585#M30010</link>
      <description>Its difficult to explain. I just needed the macro for another code. The datas i used have e.g. the variable name "mrz_test" "apr_test" and so on. With the new macro i want to address this variable names via &amp;amp;test_a.test. And i dont want to give test_a the value "mrz" directly, because i already have so many different macros in my code.&lt;BR /&gt;&lt;BR /&gt;Thanks to PaigeMiller i managed to get the english month-names (Mar, May, Oct, Dec) but not the german ones (Mrz, Mai, Okt, Dez). So i changed all variable names into english and now i'm happy :D. My Code do what it is made for.</description>
      <pubDate>Wed, 21 Jul 2021 10:15:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/755585#M30010</guid>
      <dc:creator>Hansi_12345</dc:creator>
      <dc:date>2021-07-21T10:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: Define a macro with an if-condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/755616#M30030</link>
      <description>&lt;P&gt;Since there are only 12 months you could just write your own logic for converting month number to whatever string you want. For example you could just type out the 12 strings yourself and use %SCAN() to pick the right one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro german_month(date);
%scan(Jan ... Dez,%sysfunc(month(&amp;amp;date)))
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then call the macro were you want to generate that three letter string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let varname=%german_month("&amp;amp;sysdate9"d)_test ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jul 2021 13:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Define-a-macro-with-an-if-condition/m-p/755616#M30030</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-21T13:04:35Z</dc:date>
    </item>
  </channel>
</rss>

