<?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: Date lookup in list of dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-lookup-in-list-of-dates/m-p/680669#M205759</link>
    <description>&lt;P&gt;There are a number of problems here. The two I can see directly are&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Do not format macro variables. Leave them unformatted. &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28.&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Your&amp;nbsp;&lt;FONT face="courier new,courier"&gt;%if %sysevalf&lt;/FONT&gt; will fail if&amp;nbsp;&lt;SPAN&gt;CS_ds_DMdates contains more than one value because it is not valid SAS syntax. Your macro variables must resolve into valid SAS code, and you won't have that.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Place this command at the start of your code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then please&amp;nbsp;re-run the code after you make the changes so that the macro variables are unformatted. Show us the LOG. &lt;STRONG&gt;Paste the log into the box that appears when you click on the &amp;lt;/&amp;gt; icon here. DO NOT SKIP THIS STEP.&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Sep 2020 11:51:30 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-09-01T11:51:30Z</dc:date>
    <item>
      <title>Date lookup in list of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-lookup-in-list-of-dates/m-p/680662#M205755</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;i have an issue here in looking for a date variable in list of date variables in sas.&lt;/P&gt;&lt;P&gt;i need to run a code based on condition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;%let Daily_Dm_Load_Date =%SYSFUNC(INTNX(day,%SYSFUNC(TODAY())-1,0),date9.);&lt;BR /&gt;%let ds_dt =%SYSFUNC(INTNX(day,%SYSFUNC(TODAY()),0),date9.);&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;%put &amp;amp;Daily_Dm_Load_Date(1Sep2020);&lt;BR /&gt;%put &amp;amp;ds_dt.;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: inherit;"&gt;Proc sql;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;select distinct(dm_load_date) format date9. into: CS_ds_DMdates SEPARATED BY "," from DM.CS_90DAY_DETAILS;&lt;BR /&gt;quit;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;%put &amp;amp;CS_ds_DMdates.(25Aug2020,31Aug2020);&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;%macro Appnd ;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;options mprint mlogic symbolgen compress=yes;&lt;BR /&gt;/*delete and replacing Old &amp;nbsp;data*/&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;%if %sysevalf( "&amp;amp;Daily_Dm_Load_Date "d &amp;nbsp;ne &amp;amp;CS_ds_DMdates.) %then %do;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp; %put "it is not in the list";&lt;BR /&gt;&amp;nbsp;%else %do;&lt;BR /&gt;&amp;nbsp;%put "it is not in the list";&lt;BR /&gt;&amp;nbsp;%end;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;%mend ;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;%appnd;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;i want to&amp;nbsp; look the "Daily_Dm_Load_Date " in "CS_ds_DMdates".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can anyone help me on this.&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>Tue, 01 Sep 2020 11:11:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-lookup-in-list-of-dates/m-p/680662#M205755</guid>
      <dc:creator>sg_kr</dc:creator>
      <dc:date>2020-09-01T11:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: Date lookup in list of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-lookup-in-list-of-dates/m-p/680669#M205759</link>
      <description>&lt;P&gt;There are a number of problems here. The two I can see directly are&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Do not format macro variables. Leave them unformatted. &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28.&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Your&amp;nbsp;&lt;FONT face="courier new,courier"&gt;%if %sysevalf&lt;/FONT&gt; will fail if&amp;nbsp;&lt;SPAN&gt;CS_ds_DMdates contains more than one value because it is not valid SAS syntax. Your macro variables must resolve into valid SAS code, and you won't have that.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Place this command at the start of your code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then please&amp;nbsp;re-run the code after you make the changes so that the macro variables are unformatted. Show us the LOG. &lt;STRONG&gt;Paste the log into the box that appears when you click on the &amp;lt;/&amp;gt; icon here. DO NOT SKIP THIS STEP.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2020 11:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-lookup-in-list-of-dates/m-p/680669#M205759</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-01T11:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Date lookup in list of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-lookup-in-list-of-dates/m-p/680685#M205764</link>
      <description>&lt;P&gt;its executing without syntax error.&lt;BR /&gt;but logically not correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is the log.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;397 %let Daily_Dm_Load_Date =%SYSFUNC(INTNX(day,%SYSFUNC(TODAY())-7,0),date9.);&lt;BR /&gt;398 %let ds_dt =%SYSFUNC(INTNX(day,%SYSFUNC(TODAY()),0),date9.);&lt;BR /&gt;399 LIBNAME DM "/SASEBI/OPS/data/CS Dashboard";&lt;BR /&gt;NOTE: Libref DM was successfully assigned as follows:&lt;BR /&gt;Engine: V9&lt;BR /&gt;Physical Name: *****************&lt;BR /&gt;400 %put &amp;amp;Daily_Dm_Load_Date;&lt;BR /&gt;SYMBOLGEN: Macro variable DAILY_DM_LOAD_DATE resolves to 25AUG2020&lt;BR /&gt;25AUG2020&lt;BR /&gt;401 %put &amp;amp;ds_dt.;&lt;BR /&gt;SYMBOLGEN: Macro variable DS_DT resolves to 01SEP2020&lt;BR /&gt;01SEP2020&lt;BR /&gt;402&lt;BR /&gt;403 LIBNAME DM "***********************";&lt;BR /&gt;NOTE: Libref DM was successfully assigned as follows:&lt;BR /&gt;Engine: V9&lt;BR /&gt;Physical Name: ***************&lt;BR /&gt;404 Proc sql;&lt;BR /&gt;405 select distinct dm_load_date into: CS_ds_DMdates1 separated by ' ' from&lt;BR /&gt;405! DM.CS_90DAY_DETAILS;&lt;BR /&gt;406 quit;&lt;BR /&gt;NOTE: The PROCEDURE SQL printed page 18.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 33.66 seconds&lt;BR /&gt;cpu time 8.19 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;SYMBOLGEN: Macro variable CS_DS_DMDATES1 resolves to 25AUG2020 30AUG2020&lt;BR /&gt;407 %put &amp;amp;CS_ds_DMdates1;&lt;BR /&gt;25AUG2020 30AUG2020&lt;BR /&gt;408&lt;BR /&gt;409 options mprint;&lt;BR /&gt;410 %macro Appnd ;&lt;BR /&gt;411 LIBNAME DM ***************;&lt;BR /&gt;412 options mprint mlogic symbolgen compress=yes;&lt;BR /&gt;413&lt;BR /&gt;414 /* */&lt;BR /&gt;415 %if ( &amp;amp;Daily_Dm_Load_Date ne &amp;amp;CS_ds_DMdates1.) %then %do;&lt;BR /&gt;416&lt;BR /&gt;417 %put "it is not in the list";&lt;BR /&gt;418 %end;&lt;BR /&gt;419&lt;BR /&gt;420 %else %do;&lt;BR /&gt;421&lt;BR /&gt;422 %put "it is in the list";&lt;BR /&gt;423 %end;&lt;BR /&gt;424 %mend ;&lt;BR /&gt;425 %appnd;&lt;BR /&gt;MLOGIC(APPND): Beginning execution.&lt;BR /&gt;&lt;BR /&gt;MPRINT(APPND): options mprint mlogic symbolgen compress=yes;&lt;BR /&gt;SYMBOLGEN: Macro variable DAILY_DM_LOAD_DATE resolves to 25AUG2020&lt;BR /&gt;SYMBOLGEN: Macro variable CS_DS_DMDATES1 resolves to 25AUG2020 30AUG2020&lt;BR /&gt;MLOGIC(APPND): %IF condition ( &amp;amp;Daily_Dm_Load_Date ne &amp;amp;CS_ds_DMdates1.) is TRUE&lt;BR /&gt;MLOGIC(APPND): %PUT "it is not in the list"&lt;BR /&gt;"it is not in the list"&lt;BR /&gt;MLOGIC(APPND): Ending execution.&lt;BR /&gt;NOTE: Remote submit to GRID complete.&lt;BR /&gt;NOTE: Remote submit to SSASGRS complete.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2020 13:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-lookup-in-list-of-dates/m-p/680685#M205764</guid>
      <dc:creator>sg_kr</dc:creator>
      <dc:date>2020-09-01T13:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: Date lookup in list of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-lookup-in-list-of-dates/m-p/680756#M205811</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215304"&gt;@sg_kr&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;its executing without syntax error.&lt;BR /&gt;but logically not correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is the log.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;397 %let Daily_Dm_Load_Date =%SYSFUNC(INTNX(day,%SYSFUNC(TODAY())-7,0),date9.);&lt;BR /&gt;398 %let ds_dt =%SYSFUNC(INTNX(day,%SYSFUNC(TODAY()),0),date9.);&lt;BR /&gt;399 LIBNAME DM "/SASEBI/OPS/data/CS Dashboard";&lt;BR /&gt;NOTE: Libref DM was successfully assigned as follows:&lt;BR /&gt;Engine: V9&lt;BR /&gt;Physical Name: *****************&lt;BR /&gt;400 %put &amp;amp;Daily_Dm_Load_Date;&lt;BR /&gt;SYMBOLGEN: Macro variable DAILY_DM_LOAD_DATE resolves to 25AUG2020&lt;BR /&gt;25AUG2020&lt;BR /&gt;401 %put &amp;amp;ds_dt.;&lt;BR /&gt;SYMBOLGEN: Macro variable DS_DT resolves to 01SEP2020&lt;BR /&gt;01SEP2020&lt;BR /&gt;402&lt;BR /&gt;403 LIBNAME DM "***********************";&lt;BR /&gt;NOTE: Libref DM was successfully assigned as follows:&lt;BR /&gt;Engine: V9&lt;BR /&gt;Physical Name: ***************&lt;BR /&gt;404 Proc sql;&lt;BR /&gt;405 select distinct dm_load_date into: CS_ds_DMdates1 separated by ' ' from&lt;BR /&gt;405! DM.CS_90DAY_DETAILS;&lt;BR /&gt;406 quit;&lt;BR /&gt;NOTE: The PROCEDURE SQL printed page 18.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 33.66 seconds&lt;BR /&gt;cpu time 8.19 seconds&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;SYMBOLGEN: Macro variable CS_DS_DMDATES1 resolves to 25AUG2020 30AUG2020&lt;BR /&gt;407 %put &amp;amp;CS_ds_DMdates1;&lt;BR /&gt;25AUG2020 30AUG2020&lt;BR /&gt;408&lt;BR /&gt;409 options mprint;&lt;BR /&gt;410 %macro Appnd ;&lt;BR /&gt;411 LIBNAME DM ***************;&lt;BR /&gt;412 options mprint mlogic symbolgen compress=yes;&lt;BR /&gt;413&lt;BR /&gt;414 /* */&lt;BR /&gt;415 %if ( &amp;amp;Daily_Dm_Load_Date ne &amp;amp;CS_ds_DMdates1.) %then %do;&lt;BR /&gt;416&lt;BR /&gt;417 %put "it is not in the list";&lt;BR /&gt;418 %end;&lt;BR /&gt;419&lt;BR /&gt;420 %else %do;&lt;BR /&gt;421&lt;BR /&gt;422 %put "it is in the list";&lt;BR /&gt;423 %end;&lt;BR /&gt;424 %mend ;&lt;BR /&gt;425 %appnd;&lt;BR /&gt;MLOGIC(APPND): Beginning execution.&lt;BR /&gt;&lt;BR /&gt;MPRINT(APPND): options mprint mlogic symbolgen compress=yes;&lt;BR /&gt;SYMBOLGEN: Macro variable DAILY_DM_LOAD_DATE resolves to 25AUG2020&lt;BR /&gt;SYMBOLGEN: Macro variable CS_DS_DMDATES1 resolves to 25AUG2020 30AUG2020&lt;BR /&gt;MLOGIC(APPND): %IF condition ( &amp;amp;Daily_Dm_Load_Date ne &amp;amp;CS_ds_DMdates1.) is TRUE&lt;BR /&gt;MLOGIC(APPND): %PUT "it is not in the list"&lt;BR /&gt;"it is not in the list"&lt;BR /&gt;MLOGIC(APPND): Ending execution.&lt;BR /&gt;NOTE: Remote submit to GRID complete.&lt;BR /&gt;NOTE: Remote submit to SSASGRS complete.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would suspect that the "logically not correct" is coming from your variable CS_DS_DMDATES1 .&lt;/P&gt;
&lt;P&gt;Note this line in your log:&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable CS_DS_DMDATES1 resolves to 25AUG2020 30AUG2020&lt;/P&gt;
&lt;P&gt;So CS_DS_DMDATES1 contains a string that looks like &lt;STRONG&gt;2 dates.&lt;/STRONG&gt; Which is NOT equal to the variable DAILY_DM_LOAD_DATE which contains a single value of&amp;nbsp;25AUG2020 .&amp;nbsp; So&amp;nbsp;25AUG2020&amp;nbsp; is not equal to&amp;nbsp; 25AUG2020 30AUG2020. If you want to compare a single value to multiple then you would use an&lt;STRONG&gt; IN&lt;/STRONG&gt; comparison or parse the second list of values one at a time. &lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2020 16:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-lookup-in-list-of-dates/m-p/680756#M205811</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-01T16:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Date lookup in list of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-lookup-in-list-of-dates/m-p/680769#M205816</link>
      <description>&lt;P&gt;This problem is the problem I was referring to in my comment #2 above. This line&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if ( &amp;amp;Daily_Dm_Load_Date ne &amp;amp;CS_ds_DMdates1.) %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;resolves to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if ( 25AUG2020 ne 25AUG2020 30AUG2020) %then %do;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can you see why this won't work? Do you see the syntax error here? A fundamental principle of writing macros is that when the macro variable is replaced by its value, it must produce working SAS code, and that didn't happen here. Can you re-write this statement without macro varialbes so that it is valid SAS code? If so, then you can drop macro variable in and it has a much better chance of working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you are still formatting your macro variables, this is not a good thing to do, leave them unformatted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2020 17:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-lookup-in-list-of-dates/m-p/680769#M205816</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-01T17:26:02Z</dc:date>
    </item>
  </channel>
</rss>

