<?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 SAS Queries in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/SAS-Queries/m-p/595998#M15881</link>
    <description>&lt;P&gt;May I know how to get the "events" into the project dataset when the period is in between the event startdate and enddate?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Project;&lt;BR /&gt;format Period Date9.;&lt;BR /&gt;input Period Date9. Project $;&lt;BR /&gt;datalines;&lt;BR /&gt;12JAN2019 ProjectA&lt;BR /&gt;16FEB2019 ProjectB&lt;BR /&gt;17APR2019 ProjectC&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;data Event;&lt;BR /&gt;FORMAT DATESTART DATE9.; FORMAT DATEEND DATE9.;&lt;BR /&gt;input DATESTART:DATE9. DATEEND:DATE9. EVENT $10.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;01JAN2019 12JAN2019 TESTING_A&lt;BR /&gt;13JAN2019 17FEB2019 TESTING_B&lt;BR /&gt;15FEB2019 18APR2019 TESTING_C&lt;/P&gt;&lt;P&gt;02MAY2019 04MAY2019 TESTING_D&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My desired result will be:&lt;/P&gt;&lt;P&gt;Period &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; Project &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Event&lt;/P&gt;&lt;P&gt;12JAN2019 ProjectA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TESTING_A&lt;BR /&gt;16FEB2019 ProjectB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TESTING_B, TESTING_C&lt;BR /&gt;17APR2019 ProjectC &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TESTING_C&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea? Thanks.&lt;/P&gt;</description>
    <pubDate>Sun, 13 Oct 2019 01:51:07 GMT</pubDate>
    <dc:creator>scb</dc:creator>
    <dc:date>2019-10-13T01:51:07Z</dc:date>
    <item>
      <title>SAS Queries</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Queries/m-p/595998#M15881</link>
      <description>&lt;P&gt;May I know how to get the "events" into the project dataset when the period is in between the event startdate and enddate?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Project;&lt;BR /&gt;format Period Date9.;&lt;BR /&gt;input Period Date9. Project $;&lt;BR /&gt;datalines;&lt;BR /&gt;12JAN2019 ProjectA&lt;BR /&gt;16FEB2019 ProjectB&lt;BR /&gt;17APR2019 ProjectC&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;data Event;&lt;BR /&gt;FORMAT DATESTART DATE9.; FORMAT DATEEND DATE9.;&lt;BR /&gt;input DATESTART:DATE9. DATEEND:DATE9. EVENT $10.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;01JAN2019 12JAN2019 TESTING_A&lt;BR /&gt;13JAN2019 17FEB2019 TESTING_B&lt;BR /&gt;15FEB2019 18APR2019 TESTING_C&lt;/P&gt;&lt;P&gt;02MAY2019 04MAY2019 TESTING_D&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My desired result will be:&lt;/P&gt;&lt;P&gt;Period &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; Project &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Event&lt;/P&gt;&lt;P&gt;12JAN2019 ProjectA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TESTING_A&lt;BR /&gt;16FEB2019 ProjectB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TESTING_B, TESTING_C&lt;BR /&gt;17APR2019 ProjectC &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TESTING_C&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea? Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Oct 2019 01:51:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Queries/m-p/595998#M15881</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2019-10-13T01:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Queries</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Queries/m-p/596003#M15882</link>
      <description>&lt;P&gt;By what rule does your PROJECTA (date=12JAN2019) match with the EVENT of TESTINGA (with dates 01JAN2019 through 11JAN2019)?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Oct 2019 23:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Queries/m-p/596003#M15882</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-12T23:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Queries</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Queries/m-p/596020#M15885</link>
      <description>&lt;P&gt;I have rectified the code, thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Oct 2019 01:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Queries/m-p/596020#M15885</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2019-10-13T01:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Queries</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Queries/m-p/596025#M15886</link>
      <description>&lt;P&gt;One approach to this is to read is to build a daily calendar from the date ranges in the EVENT dataset.&amp;nbsp; That calendar can be an array of character values, indexed by the date range of your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's say that you expect only dates in 2019.&amp;nbsp; Then an array with lower bound equivalent to 01jan2019 and upper bound equivalent to 31dec2019 could store a set of 40-character elements,&amp;nbsp; where each element can store a comma-separated list of events corresponding to that date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you could read in PROJECT dataset, look up the PERIOD date in the array, and retrieve the corresponding event list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Project;
format Period Date9.;
input Period Date9. Project $;
datalines;
12JAN2019 ProjectA
16FEB2019 ProjectB
17APR2019 ProjectC
RUN;

data Event;
FORMAT DATESTART DATE9.; FORMAT DATEEND DATE9.;
input DATESTART DATE9. DATEEND  :DATE9. EVENT $10.;
DATALINES;
01JAN2019 12JAN2019 TESTING_A
13JAN2019 17FEB2019 TESTING_B
15FEB2019 18APR2019 TESTING_C
02MAY2019 04MAY2019 TESTING_D
RUN;

%let lower_bound=%sysfunc(inputn(01jan2019,date9.));
%let upper_bound=%sysfunc(inputn(30jun2019,date9.));

data want (keep=period project event_list);
  array test_list {&amp;amp;lower_bound:&amp;amp;upper_bound} $40 _temporary_;
  set event (in=inE) project (in=inP);
  if inE then do d=datestart to dateend;  
     test_list{d}=catx(',',test_list{d},event);
  end;
  if inP;
  event_list=test_list{period};
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The %let lower_bound=&amp;nbsp; statement tells sas to make a macro variable LOWER_BOUND with the numeric value of 01jan2019 (01jan1960 is value zero).&amp;nbsp; The you can use the macrovars LOWER_BOUND and UPPER_BOUND as array limits.&lt;/LI&gt;
&lt;LI&gt;The SET statement reads all the EVENT records first, then all the PROJECT records.&amp;nbsp; If the record-in-hand is an event record (inE is true), then update each date in the array from DATESTART to DATEEND.&lt;/LI&gt;
&lt;LI&gt;The "if inP" statement is a subsetting if, so only PROJECT records pass this filter.&lt;/LI&gt;
&lt;LI&gt;Finally, retrieve the construct calendar entry for the PERIOD date.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just be sure to (1) have LOWER_BOUND and UPPER_BOUND cover your entire date range, and (2) use a character lenght ($40 above) long enough to cover the busiest date in your study.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Oct 2019 03:21:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Queries/m-p/596025#M15886</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-13T03:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Queries</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Queries/m-p/596053#M15890</link>
      <description>&lt;P&gt;In order to not have your code mangled, &lt;STRONG&gt;&lt;FONT size="4"&gt;ALWAYS&lt;/FONT&gt; &lt;/STRONG&gt;post code using the "little running man" icon. PLEASE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data project;
format period date9.;
input period :Date9. project $;
datalines;
12JAN2019 ProjectA
16FEB2019 ProjectB
17APR2019 ProjectC
;
run;

data event;
format datestart dateend date9.;
input datestart :date9. dateend :date9. event :$10.;
datalines;
01JAN2019 12JAN2019 TESTING_A
13JAN2019 17FEB2019 TESTING_B
15FEB2019 18APR2019 TESTING_C
02MAY2019 04MAY2019 TESTING_D
;
run;

proc sql;
create table want_int as
select
  a.*,
  b.event as _event
from
  project a
  left join
  event b
on a.period between b.datestart and b.dateend
;
quit;

data want;
set want_int;
by project;
retain event;
length event $100;
if first.project then event = "";
event = catx(',',event,_event);
if last.project;
drop _event;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Oct 2019 09:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Queries/m-p/596053#M15890</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-13T09:40:13Z</dc:date>
    </item>
  </channel>
</rss>

