<?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: Problem with inserting DATE from a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852048#M336805</link>
    <description>&lt;P&gt;Here is an obvious over complication:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET LOOP = 1;
%DO %WHILE (&amp;amp;LOOP &amp;lt;= 4);
...
%LET LOOP=%SYSEVALF(&amp;amp;LOOP+1);
%END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want LOOP to iterate from from 1 to 4 just say that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%DO LOOP=1 %to 4 ;
...
%END;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 Jan 2023 23:58:08 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-01-03T23:58:08Z</dc:date>
    <item>
      <title>Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852041#M336798</link>
      <description>&lt;P&gt;Hello Everyone&lt;/P&gt;&lt;P&gt;I am trying to run the following macro. The macro itself is working fine; however, there is an error when SAS executes&amp;nbsp;DATE = &amp;amp;QUARTER_DAY_START TO &amp;amp;QUARTER_DAY_END; if I remove the "IF"&amp;nbsp; and run the code, the log will be (at end of the code)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO AN_COST();&lt;BR /&gt;%LOCAL LOOP;&lt;BR /&gt;%LET LOOP = 1;&lt;/P&gt;&lt;P&gt;%DO %WHILE (&amp;amp;LOOP &amp;lt;= 4);&lt;BR /&gt;%LET DAYS= %EVAL( %SYSFUNC(INTNX(QTR,'01JAN2022'D, (&amp;amp;LOOP-1), E))-%SYSFUNC(INTNX(QTR,'01JAN2022'D, (&amp;amp;LOOP-1), B)) + 1);&lt;BR /&gt;%LET QUARTER_DAY_START = %SYSFUNC(DEQUOTE(" '%SYSFUNC(INTNX(MONTH, '01JAN2022'D, (&amp;amp;LOOP-1)*3, B), DATE11.)' "));&lt;BR /&gt;%LET QUARTER_DAY_END = %SYSFUNC(DEQUOTE(" '%SYSFUNC(INTNX(MONTH, '01JAN2022'D, ((&amp;amp;LOOP-1)*3)+ 2, E), DATE11.)' "));&lt;BR /&gt;%PUT &amp;amp;=DAYS;&lt;BR /&gt;%PUT &amp;amp;=QUARTER_DAY_START;&lt;BR /&gt;%PUT &amp;amp;=QUARTER_DAY_END;&lt;/P&gt;&lt;P&gt;DATA WORK.MY_NEW_TABLE;&lt;BR /&gt;SET WORK.MY_OLD_TABLE;&lt;/P&gt;&lt;P&gt;%IF MARKET = XXX %THEN&lt;BR /&gt;%DO;&lt;BR /&gt;DATE = &amp;amp;QUARTER_DAY_START TO &amp;amp;QUARTER_DAY_END;&lt;BR /&gt;OUTPUT;&lt;BR /&gt;%END;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;%LET LOOP=%SYSEVALF(&amp;amp;LOOP+1);&lt;BR /&gt;%END;&lt;BR /&gt;%MEND;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LOG:&lt;/P&gt;&lt;P&gt;13 DATE = &amp;amp;QUARTER_DAY_START TO QUARTER_DAY_END;&lt;BR /&gt;__&lt;BR /&gt;388&lt;BR /&gt;202&lt;BR /&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;&lt;P&gt;ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 23:25:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852041#M336798</guid>
      <dc:creator>Emoji</dc:creator>
      <dc:date>2023-01-03T23:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852042#M336799</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF MARKET = XXX %THEN /* this condition can never be true; the string MARKET is not equal to the string XXX */
%DO;
DATE = &amp;amp;QUARTER_DAY_START TO &amp;amp;QUARTER_DAY_END; /* this is an invalid data step statement, TO is not a numeric operator */ */
OUTPUT;
%END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But why are you still doing this stupidity:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET QUARTER_DAY_START = %SYSFUNC(DEQUOTE(" '%SYSFUNC(INTNX(MONTH, '01JAN2022'D, (&amp;amp;LOOP-1)*3, B), DATE11.)' "));
%LET QUARTER_DAY_END = %SYSFUNC(DEQUOTE(" '%SYSFUNC(INTNX(MONTH, '01JAN2022'D, ((&amp;amp;LOOP-1)*3)+ 2, E), DATE11.)' "));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;???&lt;/P&gt;
&lt;P&gt;I have already shown you how to store dates in macro variable for later use in code.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 23:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852042#M336799</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-03T23:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852043#M336800</link>
      <description>Thanks for the reply. Please be advised that if I manually enter the date as follows, the code will work without any issues:&lt;BR /&gt;if Market = 'MARKET_2022' then do Date = '01-JAN-2022'd to '31-MAR-2022'd;</description>
      <pubDate>Tue, 03 Jan 2023 23:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852043#M336800</guid>
      <dc:creator>Emoji</dc:creator>
      <dc:date>2023-01-03T23:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852044#M336801</link>
      <description>&lt;P&gt;Post log in a text box opened with the &amp;lt;/&amp;gt; icon at the top of the message window. Then the _ character will appear under the text that SAS says causes the syntax error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As we mentioned in your previous post about INTNX formatted text values of dates are not actual date values and cannot be used in assignments or comparisons without extra work.&lt;/P&gt;
&lt;PRE&gt;DATE = &amp;amp;QUARTER_DAY_START TO &amp;amp;QUARTER_DAY_END;&lt;/PRE&gt;
&lt;P&gt;You are asking for something like&lt;/P&gt;
&lt;PRE&gt;date = 01-JAN-2022 to 31-MAR-2022;&lt;/PRE&gt;
&lt;P&gt;You do not have a data step DO loop but mix bits from what should be : Do date= &amp;lt;start value&amp;gt; to &amp;lt;end value&amp;gt;;&lt;/P&gt;
&lt;P&gt;as %do; &amp;lt;macro instruction&amp;gt;&lt;/P&gt;
&lt;P&gt;date = 01-JAN-2022 to 31-MAR-2022;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;which is not a valid assignment statement for multiple reasons and not valid loop code either. You have to keep macro statements, %do / %end and data step statements do/end separate and know when you want which.&lt;/P&gt;
&lt;P&gt;Did you have a working data step for a loop of dates before you began this? Look closely at it. If not, make sure you have one that works for a set of values and then compare with the code in your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To debug your macro code as it generates run: Options Mprint; before running your macro. It will show the statements generated. If you have Logic issues in the macro include Mlogic and if you have creation / resolution of macro variables add Symbolgen to the options statement.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 23:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852044#M336801</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-03T23:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852045#M336802</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314145"&gt;@Emoji&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks for the reply. Please be advised that if I manually enter the date as follows, the code will work without any issues:&lt;BR /&gt;if Market = 'MARKET_2022' then do Date = '01-JAN-2022'd to '31-MAR-2022'd;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The code generated by your macro does not look like that. Use the Options MPRINT to confirm that.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 23:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852045#M336802</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-03T23:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852046#M336803</link>
      <description>&lt;P&gt;This is a flaw in logic and you're mixing macro and data step logic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Market is a variable in your data set it seems and macro IF statement code will not access the variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are you trying to do overall? Add records?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI - I actually doubt you need macro logic anywhere in this code but if you show a small example of what you're trying to accomplish we can help you simplify your code.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;EDIT: Isn't that the wrong code as well from an earlier post for your macro variable creation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314145"&gt;@Emoji&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello Everyone&lt;/P&gt;
&lt;P&gt;I am trying to run the following macro. The macro itself is working fine; however, there is an error when SAS executes&amp;nbsp;DATE = &amp;amp;QUARTER_DAY_START TO &amp;amp;QUARTER_DAY_END; if I remove the "IF"&amp;nbsp; and run the code, the log will be (at end of the code)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%MACRO AN_COST();&lt;BR /&gt;%LOCAL LOOP;&lt;BR /&gt;%LET LOOP = 1;&lt;/P&gt;
&lt;P&gt;%DO %WHILE (&amp;amp;LOOP &amp;lt;= 4);&lt;BR /&gt;%LET DAYS= %EVAL( %SYSFUNC(INTNX(QTR,'01JAN2022'D, (&amp;amp;LOOP-1), E))-%SYSFUNC(INTNX(QTR,'01JAN2022'D, (&amp;amp;LOOP-1), B)) + 1);&lt;BR /&gt;%LET QUARTER_DAY_START = %SYSFUNC(DEQUOTE(" '%SYSFUNC(INTNX(MONTH, '01JAN2022'D, (&amp;amp;LOOP-1)*3, B), DATE11.)' "));&lt;BR /&gt;%LET QUARTER_DAY_END = %SYSFUNC(DEQUOTE(" '%SYSFUNC(INTNX(MONTH, '01JAN2022'D, ((&amp;amp;LOOP-1)*3)+ 2, E), DATE11.)' "));&lt;BR /&gt;%PUT &amp;amp;=DAYS;&lt;BR /&gt;%PUT &amp;amp;=QUARTER_DAY_START;&lt;BR /&gt;%PUT &amp;amp;=QUARTER_DAY_END;&lt;/P&gt;
&lt;P&gt;DATA WORK.MY_NEW_TABLE;&lt;BR /&gt;SET WORK.MY_OLD_TABLE;&lt;/P&gt;
&lt;P&gt;%IF MARKET = XXX %THEN&lt;BR /&gt;%DO;&lt;BR /&gt;DATE = &amp;amp;QUARTER_DAY_START TO &amp;amp;QUARTER_DAY_END;&lt;BR /&gt;OUTPUT;&lt;BR /&gt;%END;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;%LET LOOP=%SYSEVALF(&amp;amp;LOOP+1);&lt;BR /&gt;%END;&lt;BR /&gt;%MEND;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LOG:&lt;/P&gt;
&lt;P&gt;13 DATE = &amp;amp;QUARTER_DAY_START TO QUARTER_DAY_END;&lt;BR /&gt;__&lt;BR /&gt;388&lt;BR /&gt;202&lt;BR /&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;
&lt;P&gt;ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 23:56:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852046#M336803</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-03T23:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852047#M336804</link>
      <description>&lt;P&gt;Here is one obvious mistake:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF MARKET = XXX %THEN %DO;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The string MARKET is NEVER going to equal the string XXX.&amp;nbsp; It cannot happen.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 23:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852047#M336804</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-03T23:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852048#M336805</link>
      <description>&lt;P&gt;Here is an obvious over complication:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET LOOP = 1;
%DO %WHILE (&amp;amp;LOOP &amp;lt;= 4);
...
%LET LOOP=%SYSEVALF(&amp;amp;LOOP+1);
%END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want LOOP to iterate from from 1 to 4 just say that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%DO LOOP=1 %to 4 ;
...
%END;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Jan 2023 23:58:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852048#M336805</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-03T23:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852049#M336806</link>
      <description>&lt;P&gt;Are you just trying to do this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.MY_NEW_TABLE;
  SET WORK.MY_OLD_TABLE;
  if market = xxx then do qtr=1 to 4;
    do date = intnx('qtr','01jan2022'd,qtr-1,'b') to intnx('qtr','01jan2022'd,qtr-1,'e');
      OUTPUT;
    end;
  end;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What are the variables MARKET and XXX?&amp;nbsp; Why does it matter whether they are equal or not?&amp;nbsp; Do you need to attach a format to the DATE variable?&amp;nbsp; Is it a NEW variable or did it already exist in MY_OLD_TABLE?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 00:10:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852049#M336806</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-04T00:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852050#M336807</link>
      <description>&lt;P&gt;Variable Market is a variable (string) from Work.my_old_table. By using Market = XXX, I was trying to say that the when String market is XXX (in reality it is something like 'market_data', the rest of the code should be executed.&lt;/P&gt;&lt;P&gt;I ran the code that you shared and got the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;49 date = intnx('qtr','01jan2022'd,qtr-1,'b') to intnx('qtr','01jan2022'd,qtr-1,'e');&lt;BR /&gt;__&lt;BR /&gt;22&lt;BR /&gt;2 The SAS System 06:13 Tuesday, December 13, 2022&lt;/P&gt;&lt;P&gt;202&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, ;, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT,&lt;BR /&gt;IN, LE, LT, MAX, MIN, NE, NG, NL, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.&lt;/P&gt;&lt;P&gt;ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 00:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852050#M336807</guid>
      <dc:creator>Emoji</dc:creator>
      <dc:date>2023-01-04T00:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852051#M336808</link>
      <description>&lt;P&gt;&lt;STRONG&gt;ALWAYS&lt;/STRONG&gt; post complete logs of a step. Without context, one line and an error message is mostly useless.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 00:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852051#M336808</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-04T00:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852052#M336809</link>
      <description>Thanks for the reply. Let's forget about this equality constraints as I wrote to simplify my code for representation here. In my actual code, variable Market has different values.</description>
      <pubDate>Wed, 04 Jan 2023 00:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852052#M336809</guid>
      <dc:creator>Emoji</dc:creator>
      <dc:date>2023-01-04T00:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852053#M336810</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314145"&gt;@Emoji&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;if Market = 'MARKET_2022' then do Date = '01-JAN-2022'd to '31-MAR-2022'd;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;This&amp;nbsp;&lt;/STRONG&gt;is a&amp;nbsp;&lt;STRONG&gt;DATA STEP&lt;/STRONG&gt;&amp;nbsp;IF statement. What you posted previously was a&amp;nbsp;&lt;STRONG&gt;MACRO&lt;/STRONG&gt;&amp;nbsp;%IF statement.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 00:26:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852053#M336810</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-04T00:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852054#M336811</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314145"&gt;@Emoji&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks for the reply. Let's forget about this equality constraints as I wrote to simplify my code for representation here. In my actual code, variable Market has different values.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But the&amp;nbsp;&lt;U&gt;macro&lt;/U&gt; %IF does not work with data step variables, it only "sees"&amp;nbsp;&lt;U&gt;text&lt;/U&gt;. It creates code before the data step is even compiled.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 00:30:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852054#M336811</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-04T00:30:13Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852073#M336826</link>
      <description>&lt;P&gt;I believe you get the error because of a missing DO statement.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1672798906254.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79021iA6D3751DA5C9C72A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1672798906254.png" alt="Patrick_0-1672798906254.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If I understand right what you're after then both of below two options should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Option 1:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  format date date9.;
  do qtr=1 to 4;
    do date = intnx('qtr','01jan2022'd,qtr-1,'b') to intnx('qtr','01jan2022'd,qtr-1,'e');
      output;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Option 2:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  format date date9.;
  do date = '01jan2022'd to '31dec2022'd;
    qtr=qtr(date);
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 02:31:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852073#M336826</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-01-04T02:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852074#M336827</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314145"&gt;@Emoji&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Variable Market is a variable (string) from Work.my_old_table. By using Market = XXX, I was trying to say that the when String market is XXX (in reality it is something like 'market_data', the rest of the code should be executed.&lt;/P&gt;
&lt;P&gt;I ran the code that you shared and got the following error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;49 date = intnx('qtr','01jan2022'd,qtr-1,'b') to intnx('qtr','01jan2022'd,qtr-1,'e');&lt;BR /&gt;__&lt;BR /&gt;22&lt;BR /&gt;2 The SAS System 06:13 Tuesday, December 13, 2022&lt;/P&gt;
&lt;P&gt;202&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, ;, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT,&lt;BR /&gt;IN, LE, LT, MAX, MIN, NE, NG, NL, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.&lt;/P&gt;
&lt;P&gt;ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To test a variable's value you need to use SAS code, not MACRO code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no way that the code I posted would produce that message.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you removed the DO keyword from the DO loop.&lt;/P&gt;
&lt;P&gt;The syntax for an iterative DO loop is&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;do &amp;lt;varname&amp;gt; = &amp;lt;initial value&amp;gt; [to &amp;lt;final_value&amp;gt;] [ by &amp;lt;increment&amp;gt; ] ;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Jan 2023 02:53:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852074#M336827</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-04T02:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852122#M336848</link>
      <description>&lt;P&gt;You don't state what this code is supposed to be doing, and it is always helpful to state what the code is supposed to be doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you are trying to compute the number of days in a quarter by using a loop, and it was &lt;A href="https://communities.sas.com/t5/SAS-Programming/Problem-with-INTNX/m-p/852028#M336792" target="_self"&gt;already explained&lt;/A&gt; in your earlier thread that loops are not needed to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So that's my guess anyway. Regardless, tell us the purpose of this code, tell us what it is supposed to be doing. Whatever the purpose, you have adopted a very difficult approach to get this done, and if we only knew what you were doing, I'm sure many people could suggest simpler and faster ways to do what you want.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 16:01:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852122#M336848</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-04T16:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with inserting DATE from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852139#M336856</link>
      <description>&lt;P&gt;I like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;'s second solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data my_new_table;&lt;BR /&gt;  set my_old_table;
  format date date9.;
  if market = "xxxx" then do date = '01jan2022'd to '31dec2022'd;
    qtr=qtr(date);
    output;
  end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You say you want to calculate the number of days in each quarter but don't show how it's used.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If after all this you still do not have a solution that works, I would suggest taking a step back as this is definitely an &lt;A href="https://xyproblem.info/" target="_self"&gt;xy problem&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Rather than posting your non working code, please show us a small sample of your input data and what you want as output instead.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 16:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-inserting-DATE-from-a-macro-variable/m-p/852139#M336856</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-04T16:37:49Z</dc:date>
    </item>
  </channel>
</rss>

