<?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: Macro Variable with list of dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-with-list-of-dates/m-p/551051#M153066</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datevar =20171031,20171204;

proc sql outobs=;
select code, enddate format=yymmdd10.
from data
where findw("&amp;amp;datevar.", put(enddate,yymmddn8.),",")
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 15 Apr 2019 13:58:13 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2019-04-15T13:58:13Z</dc:date>
    <item>
      <title>Macro Variable with list of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-with-list-of-dates/m-p/551040#M153058</link>
      <description>&lt;P&gt;How do I create a macro variable with a list of dates that I can then use in the where statement in proc sql?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This example works with a single date:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data;
INFILE DATALINES DLM='|';
Input CODE: 3. enddate:yymmdd10.;
datalines;
10|20170905
11|20171031
12|20171103
13|20171204
;
run;

%let datevar0 = 20171031;
%let datevar=%sysfunc(inputn(&amp;amp;datevar0,yymmdd10.), date9.);

proc sql outobs=;
select code, enddate format=yymmdd10. from data
where enddate = "&amp;amp;datevar"d
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to so is create a variable with multiple dates like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datevar = (20171031,20171204);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...and then use proc sql like this (this doesn't work but hopefully it illustrates what I'm trying to accomplish):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql outobs=;
select code, enddate format=yymmdd10. from data
where enddate in ("&amp;amp;datevar"d)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 13:40:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-with-list-of-dates/m-p/551040#M153058</guid>
      <dc:creator>tedway</dc:creator>
      <dc:date>2019-04-15T13:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable with list of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-with-list-of-dates/m-p/551047#M153064</link>
      <description>&lt;P&gt;You need to create date-literals for each value in the list, e.g. with proc sql:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select cat(quote(put(enddate, date9.)), 'd') 
        into :dateList separated by ',' 
        from data;
quit;

%put &amp;amp;=dateList;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 13:50:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-with-list-of-dates/m-p/551047#M153064</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-04-15T13:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable with list of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-with-list-of-dates/m-p/551051#M153066</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datevar =20171031,20171204;

proc sql outobs=;
select code, enddate format=yymmdd10.
from data
where findw("&amp;amp;datevar.", put(enddate,yymmddn8.),",")
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 13:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-with-list-of-dates/m-p/551051#M153066</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-04-15T13:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable with list of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-with-list-of-dates/m-p/551061#M153071</link>
      <description>&lt;P&gt;First a couple of points.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;It is much easier in SAS to use space delimited lists.&amp;nbsp; Commas as the delimiter will make coding much harder.&amp;nbsp; So if your values contain spaces then use some other character that does not appear in the data like a pipe | or a caret ^ as the delimiter.&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;The strings you have are not yet dates. They might look like dates to you but they don't look like dates to SAS.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Can you start with real date values?&amp;nbsp; Either date literals like "31OCT2017"D, or the actual number of days like&amp;nbsp; 21123. If so then it is easy.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datevar = 21123 "04DEC2017"d;
proc print data=data;
 where enddate in (&amp;amp;datevar) ;
 var code enddate;
 format enddate yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If not then convert your original macro variable to a new one that you can use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro convert_ymd2date(list);
%local i;
%do i=1 %to %sysfunc(countw(&amp;amp;list));
 %sysfunc(inputn(%scan(&amp;amp;list,&amp;amp;i),yymmdd10))
%end;
%mend convert_ymd2date;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then your code can be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datevar=20171031 20171204;
proc sql outobs=;
select code
     , enddate format=yymmdd10. 
  from data
  where enddate in (%convert_ymd2date(&amp;amp;datevar))
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 14:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-with-list-of-dates/m-p/551061#M153071</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-15T14:44:38Z</dc:date>
    </item>
  </channel>
</rss>

