<?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: Assign events to weeks of year in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963394#M43240</link>
    <description>It's hard to tell what your desired output is.  You're just wanting to have a count of admissions by calendar week?</description>
    <pubDate>Fri, 04 Apr 2025 10:28:59 GMT</pubDate>
    <dc:creator>quickbluefish</dc:creator>
    <dc:date>2025-04-04T10:28:59Z</dc:date>
    <item>
      <title>Assign events to weeks of year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963390#M43239</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following two datasets:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date09. Discharge :date09.; 
  format Admission date9. Discharge date9.;
cards;
0001 04FEB2017 22FEB2017
0002 10JUN2017 16JUN2017
0004 29NOV2017 01DEC2017
0005 28DEC2017 05JAN2018
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB1;
  input  Start :date09. End :date09. Index; 
  format Start :date9. End :date9.;
cards;
29JAN2017 04FEB2017 1
04JUN2017 10JUN2017 1
26NOV2017 02DEC2017 1
24DEC2017 30DEC2017 1
31DEC2017 06JAN2018 1
;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Desired output:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DBx;
  input  Start :date09. End :date09. Index; 
  format Start :date9. End :date9.;
cards;
29JAN2017 04FEB2017 1
04JUN2017 10JUN2017 1
26NOV2017 02DEC2017 1
24DEC2017 30DEC2017 1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DB dataset contains a set of admissions with relative date of admission and date of discharge. The duration of the admission is not strictly one week but the time the patient needs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DB1 dataset (a small par is reported for simplicity) contains the week (Start-End) of the year where the admission occurred (referring to "Admission" variable of DB). For example, for ID 0001 the admission occurred at 04FEB2017 that is in the week 29JAN2017-04FEB2017 of year 2017.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is with ID = 0005 because two weeks are counted in DB1 but no new admission occurred for ID 0005. The patient only stayed hospitalized. The count should be 0.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here the code used to generate DB1:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro Counts(dataset);
data &amp;amp;dataset;
	set &amp;amp;dataset;
	week_begin = intnx('week', Admission, 0);
	format week_begin date9.;
run;

proc freq data=&amp;amp;dataset;
tables week_begin / out=admissions&amp;amp;dataset (keep=week_begin count rename=(count=n_&amp;amp;dataset)) noprint;
run;

proc sql;
    create table Counts_&amp;amp;dataset as
    select d1.*, d2.n_&amp;amp;dataset
    from all_weeks d1 left join admissions&amp;amp;dataset d2
            on d2.week_begin &amp;gt;= d1.admission and d2.week_begin &amp;lt;= d1.discharge
    ;
quit;


proc sort data = Counts_&amp;amp;dataset; by admission; run;


data TSM_&amp;amp;dataset; 
	set Counts_&amp;amp;dataset; 
	if missing (n_&amp;amp;dataset) then n_&amp;amp;dataset = 0;
run;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the dataset all_weeks looks like this:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data All_weeks;
  input  Admission :date09. Discharge :date09.; 
  format Admission date9. Discharge date9.;
cards;
29DEC2013 04JAN2014
05JAN2014 11JAN2014
12JAN2014 18JAN2014
19JAN2014 25JAN2014
26JAN2014 01FEB2014
.....
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can anyone help me please?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 12:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963390#M43239</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2025-04-04T12:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Assign events to weeks of year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963394#M43240</link>
      <description>It's hard to tell what your desired output is.  You're just wanting to have a count of admissions by calendar week?</description>
      <pubDate>Fri, 04 Apr 2025 10:28:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963394#M43240</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-04-04T10:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: Assign events to weeks of year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963395#M43241</link>
      <description>&lt;P&gt;Use the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n1ka2ulrvrjlasn0z7beco2yrgas.htm" target="_blank" rel="noopener"&gt;WEEK&lt;/A&gt;&amp;nbsp;function on the admission date, and then PROC FREQ to count the number of admissions per week.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 10:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963395#M43241</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-04-04T10:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Assign events to weeks of year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963396#M43242</link>
      <description>&lt;P&gt;Exactly. I just need to put the admission in the calendar week where it occurred. The problem here is that although the patient 0005 has not a new admission but he/she simply stay in hospital it is counted as a new admission.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 10:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963396#M43242</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2025-04-04T10:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Assign events to weeks of year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963402#M43243</link>
      <description>&lt;P&gt;Do you mean 0005 is counted twice (incorrectly) because this person's hospital stay spans more than one week? I think you just need to ignore the discharge date (as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16120"&gt;@Kurt&lt;/a&gt;_Bremmer says below). From what I can tell based on your request, the discharge date is irrelevant. You just need to know how many admission dates fall within a given calendar week.&amp;nbsp; That being said, I don't understand what 'index' means in DB1 (sorry, did not read all your code) and I don't understand why DB1 only contains some calendar weeks but not all.&amp;nbsp; It would be helpful to know what your desired output file would look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 11:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963402#M43243</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-04-04T11:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: Assign events to weeks of year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963403#M43244</link>
      <description>Yes, what I need is to "annotate" the week of the admission and not the stay.  Index means that there was an admission in that week.  DB1 contains only the calendar weeks where there was at least one admission based on DB. i will add the desired output.</description>
      <pubDate>Fri, 04 Apr 2025 11:59:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963403#M43244</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2025-04-04T11:59:13Z</dc:date>
    </item>
    <item>
      <title>Re: Assign events to weeks of year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963419#M43245</link>
      <description>&lt;P&gt;Do you want a count of admissions in a given week, or just a flag that there was at least one admission?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 13:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assign-events-to-weeks-of-year/m-p/963419#M43245</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-04-04T13:39:18Z</dc:date>
    </item>
  </channel>
</rss>

