<?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: IF/Then/Let in Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-Let-in-Macro/m-p/120138#M24719</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Awesome thanks! I believe that was the issue - I didn't define the year_add macro before the macro YEAR. My code now works!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you both!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My working code now reads:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let align_status = 'ALIGNED';&lt;/P&gt;&lt;P&gt;/*%let align_status = 'NOT ALIGNED';*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let year_add = ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%MACRO YEAR;&lt;/P&gt;&lt;P&gt;%if &amp;amp;align_status.= 'ALIGNED' %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let year_add = (2013);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%if &amp;amp;align_status. = 'NOT ALIGNED' %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let year_add = (2012, 2013);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%MEND YEAR;&lt;/P&gt;&lt;P&gt;%YEAR;&lt;/P&gt;&lt;P&gt;%put &amp;amp;align_status &amp;amp;year_add;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 26 Jun 2013 19:36:37 GMT</pubDate>
    <dc:creator>tk9077</dc:creator>
    <dc:date>2013-06-26T19:36:37Z</dc:date>
    <item>
      <title>IF/Then/Let in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-Let-in-Macro/m-p/120133#M24714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a quick question regarding setting up some Macros for a code I am trying to run. Is it possible to create a macro, and then do a statement along the likes of If Macro = This Then Let Macro2 = This?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did some research, and I may have the code, but I'm not entirely sure how to use it. Could any one shed some light on what I may be missing?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code is below. I want the user to select 'ALIGNED' or 'NOT ALIGNED' in the beginning of the code, and based on that selection, the code will update the year_add macro to be either 2013 or 2012,2013.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let align_status = ('ALIGNED');&lt;/P&gt;&lt;P&gt;/*%let align_status = ('NOT ALIGNED');*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if &amp;amp;align_status.= 'ALIGNED' %then %let year_add = (2013);&lt;/P&gt;&lt;P&gt;%if &amp;amp;align_status. = 'NOT ALIGNED' %then %let year_add = (2012,2013);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think the %if/%then can't be in an open code, but I have no idea how to put these into another macro and get that macro to run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help!&lt;/P&gt;&lt;P&gt;Tony&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 17:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Then-Let-in-Macro/m-p/120133#M24714</guid>
      <dc:creator>tk9077</dc:creator>
      <dc:date>2013-06-26T17:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: IF/Then/Let in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-Let-in-Macro/m-p/120134#M24715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you may be miss using terms. To me it sounds like you are setting up macro variables and need a way to selective set other macro variables. To do this you should be able to write a real sas macro that will do this. See if the following works:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro set;&lt;/P&gt;&lt;P&gt;%if &amp;amp;align_status = 'ALIGNED' %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let year_add = (2013);&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let year_add = (2012,2013);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend set;&lt;/P&gt;&lt;P&gt;%set;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;align_status&amp;nbsp; &amp;amp;year_add;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 18:22:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Then-Let-in-Macro/m-p/120134#M24715</guid>
      <dc:creator>esjackso</dc:creator>
      <dc:date>2013-06-26T18:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: IF/Then/Let in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-Let-in-Macro/m-p/120135#M24716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your help. It appears we are getting somewhere, but it is still not working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code now reads:&lt;/P&gt;&lt;P&gt;%let align_status = 'ALIGNED';&lt;/P&gt;&lt;P&gt;/*%let align_status = 'NOT ALIGNED';*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%LET start_dt = '01JAN2012'D;&lt;/P&gt;&lt;P&gt;%LET END_dt = '31DEC2012'D;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%MACRO YEAR;&lt;/P&gt;&lt;P&gt;%if &amp;amp;align_status.= 'ALIGNED' %then %do;&lt;/P&gt;&lt;P&gt;%let year_add = (2013);&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%if &amp;amp;align_status. = 'NOT ALIGNED' %then %do;&lt;/P&gt;&lt;P&gt;%let year_add = (2012,2013);&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%MEND YEAR;&lt;/P&gt;&lt;P&gt;%YEAR;&lt;/P&gt;&lt;P&gt;%put &amp;amp;align_status &amp;amp;year_add;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My error comes up when the year_add macro is needed:&lt;/P&gt;&lt;P&gt;121&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where year_add in &amp;amp;year_add.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference YEAR_ADD not resolved.&lt;/P&gt;&lt;P&gt;121&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where year_add in &amp;amp;year_add.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 76&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: (, SELECT.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried the exact same code above, and I get the same error. Is there something else we are missing?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 18:44:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Then-Let-in-Macro/m-p/120135#M24716</guid>
      <dc:creator>tk9077</dc:creator>
      <dc:date>2013-06-26T18:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: IF/Then/Let in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-Let-in-Macro/m-p/120136#M24717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your post is a little confusing because it sounds like you are using the word MACRO to refer to macro variables instead on an actual macro (defined by %MACRO / %MEND statements).&lt;/P&gt;&lt;P&gt;To execute conditional logic statements such %IF/%THEN/%ELSE you would need to define a macro and then invoke it to get it to run.&lt;/P&gt;&lt;P&gt;Note that I have removed the parenthesis and commas from your macro variable values.&amp;nbsp; You probably do not need or want them anyway.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could define a "function" style macro to help with the conversion. Such as this:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro year_add(status);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; %if "&amp;amp;status" = "ALIGNED" %then 2013;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; %else 2012 2013 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend year_add;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then you could use it like this:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let align_status=ALIGNED;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let year_add=%year_add(&amp;amp;align_status) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or you could use %SYSFUNC() to call the IFC() function instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let year_add=%sysfunc(ifc("&amp;amp;align_status"="ALIGNED",2013,2012 2013));&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 18:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Then-Let-in-Macro/m-p/120136#M24717</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-26T18:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: IF/Then/Let in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-Let-in-Macro/m-p/120137#M24718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since you had not created the macro variable YEAR_ADD before you called the macro YEAR the value was stored in the local symbol table for the macro YEAR and so it was no longer available after the macro ends. Simplest solution is to define it before calling the macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;%let align_status = 'ALIGNED';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;%let year_add = ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;%year ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;....&amp;nbsp; where year_add in &amp;amp;year_add .... &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;You will get more flexibility by removing the commas and parenthesis from your macro variables. They are not needed for use in IN operator lists.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;%let year_add = 2012 2013 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;.... where year_add in (&amp;amp;year_add) ....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 18:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Then-Let-in-Macro/m-p/120137#M24718</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-26T18:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: IF/Then/Let in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-Let-in-Macro/m-p/120138#M24719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Awesome thanks! I believe that was the issue - I didn't define the year_add macro before the macro YEAR. My code now works!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you both!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My working code now reads:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let align_status = 'ALIGNED';&lt;/P&gt;&lt;P&gt;/*%let align_status = 'NOT ALIGNED';*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let year_add = ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%MACRO YEAR;&lt;/P&gt;&lt;P&gt;%if &amp;amp;align_status.= 'ALIGNED' %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let year_add = (2013);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%if &amp;amp;align_status. = 'NOT ALIGNED' %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let year_add = (2012, 2013);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%MEND YEAR;&lt;/P&gt;&lt;P&gt;%YEAR;&lt;/P&gt;&lt;P&gt;%put &amp;amp;align_status &amp;amp;year_add;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 19:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Then-Let-in-Macro/m-p/120138#M24719</guid>
      <dc:creator>tk9077</dc:creator>
      <dc:date>2013-06-26T19:36:37Z</dc:date>
    </item>
  </channel>
</rss>

