<?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 SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/if-then-let/m-p/856281#M42125</link>
    <description>&lt;P&gt;Thank you! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Jan 2023 17:02:15 GMT</pubDate>
    <dc:creator>ccaudillo100</dc:creator>
    <dc:date>2023-01-30T17:02:15Z</dc:date>
    <item>
      <title>%if then %let</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/if-then-let/m-p/856276#M42123</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;currently I pull in&amp;nbsp;%let cdate=%sysfunc(putn("&amp;amp;sysdate9"d,YYMMDDD10.));&lt;/P&gt;
&lt;P&gt;which displays 2023-01-30&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what I would like to do is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if mo(&amp;amp;cdate) = 01 %then %let Quarter = Q1;&lt;/P&gt;
&lt;P&gt;%if mo(&amp;amp;cdate) = 04 %then %let Quarter = Q2;&lt;/P&gt;
&lt;P&gt;%if mo(&amp;amp;cdate) = 07 %then %let Quarter = Q3;&lt;/P&gt;
&lt;P&gt;%if mo(&amp;amp;cdate) = 10 %then %let Quarter = Q4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I keep running into errors. Any help is much appreciated!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This can also refer to it as months of January, April, July, October, or abbreviations. I just need it to set Quarter based on Month&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 16:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/if-then-let/m-p/856276#M42123</guid>
      <dc:creator>ccaudillo100</dc:creator>
      <dc:date>2023-01-30T16:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: %if then %let</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/if-then-let/m-p/856280#M42124</link>
      <description>&lt;P&gt;How about this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %let Quarter= Q%sysfunc(putn("&amp;amp;sysdate9"d,QTR.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/423715"&gt;@ccaudillo100&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;currently I pull in&amp;nbsp;%let cdate=%sysfunc(putn("&amp;amp;sysdate9"d,YYMMDDD10.));&lt;/P&gt;
&lt;P&gt;which displays 2023-01-30&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what I would like to do is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if mo(&amp;amp;cdate) = 01 %then %let Quarter = Q1;&lt;/P&gt;
&lt;P&gt;%if mo(&amp;amp;cdate) = 04 %then %let Quarter = Q2;&lt;/P&gt;
&lt;P&gt;%if mo(&amp;amp;cdate) = 07 %then %let Quarter = Q3;&lt;/P&gt;
&lt;P&gt;%if mo(&amp;amp;cdate) = 10 %then %let Quarter = Q4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I keep running into errors. Any help is much appreciated!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This can also refer to it as months of January, April, July, October, or abbreviations. I just need it to set Quarter based on Month&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 16:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/if-then-let/m-p/856280#M42124</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-30T16:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: %if then %let</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/if-then-let/m-p/856281#M42125</link>
      <description>&lt;P&gt;Thank you! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 17:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/if-then-let/m-p/856281#M42125</guid>
      <dc:creator>ccaudillo100</dc:creator>
      <dc:date>2023-01-30T17:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: %if then %let</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/if-then-let/m-p/856284#M42126</link>
      <description>&lt;P&gt;You are using 1) an invalid function "MO", the function would be month:&lt;/P&gt;
&lt;P&gt;2) attempting to use a datastep fuction in macro code incorrectly: MUST use %sysfunc to call ANY data step fuction&lt;/P&gt;
&lt;P&gt;3) attempting to use a date function on a string value (2023-01-30), is not a valid date value. SAS dates are numbers of days since 01Jan1960 and the Cdate value is not a number of days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to get you quarter value&lt;/P&gt;
&lt;PRE&gt;%let quarter= Q%sysfunc(qtr(%sysfunc(today())));

%put &amp;amp;quarter.  ;&lt;/PRE&gt;
&lt;P&gt;By using the letter Q immediately preceding the %sysfunc call then the function resolves the value is placed immediately after the Q So no %if %then %else code is required.&lt;/P&gt;
&lt;P&gt;Note use of the QTR function. Your %if %then %else&amp;nbsp; completely ignores what happens in other months and as long as your quarter actually aligns with calendar quarters it would be better to use the function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For any date, time or datetime values that you expect to use other functions with or comparisons to actual date, time or datetime values you should not format the macro variable.&lt;/P&gt;
&lt;P&gt;Unless you need to know the start of a SAS session instead of the current date you might consider using the TODAY function instead of that putn with "&amp;amp;sysdate9"d&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 17:03:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/if-then-let/m-p/856284#M42126</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-30T17:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: %if then %let</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/if-then-let/m-p/856286#M42127</link>
      <description>&lt;P&gt;OK - you probably don't need to do this in macro language at all - but assuming you do, the following addresses numerous issues:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="johnagalloway0_0-1675098156608.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79929iFDE5E732233D044A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="johnagalloway0_0-1675098156608.png" alt="johnagalloway0_0-1675098156608.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="johnagalloway0_1-1675098215628.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79930i37AAF8AAA22A8392/image-size/medium?v=v2&amp;amp;px=400" role="button" title="johnagalloway0_1-1675098215628.png" alt="johnagalloway0_1-1675098215628.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It is common to overthink use of macros (especially if you have just come across them) but I would achieve the same result using:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="johnagalloway0_2-1675098854206.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79931i8B4C46FC8DB5800B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="johnagalloway0_2-1675098854206.png" alt="johnagalloway0_2-1675098854206.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Good luck, Enjoy SAS.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 17:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/if-then-let/m-p/856286#M42127</guid>
      <dc:creator>johnagalloway0</dc:creator>
      <dc:date>2023-01-30T17:15:48Z</dc:date>
    </item>
  </channel>
</rss>

