<?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: Fill missing dates and set week number in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Fill-missing-dates-and-set-week-number/m-p/934381#M41997</link>
    <description>&lt;P&gt;Hi There,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you say "&lt;SPAN&gt;Moreover, I would like to fill all the remaining weeks (that here are not shown because no events are present) back and forth with respect to each date." does this mean you want to create a dataset with all weeks ranging from 2014 up to 2015 with one record per week for each month?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Jul 2024 10:24:14 GMT</pubDate>
    <dc:creator>Mazi</dc:creator>
    <dc:date>2024-07-02T10:24:14Z</dc:date>
    <item>
      <title>Fill missing dates and set week number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-missing-dates-and-set-week-number/m-p/934374#M41996</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input Admission :date09. Number;
  format Admission date9.;
cards;
15JUN2014   4
20JUL2014   2
11JAN2015   1
18JAN2015   2
;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This dataset contains number of events by dates. Each date starts the first day of the week, so Sunday.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to add the week number for each date and a variable that indicates the year (it is ok by using "year" function. I can do this). Moreover, I would like to fill all the remaining weeks (that here are not shown because no events are present) back and forth with respect to each date.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The desired output should be the following (indicative output is shown for simplicity):&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB1;
  input Admission :date09. Number Week_Number year;
  format Admission date9.;
cards;
30DEC2013   0    1   2014
06JAN2014   0    2   2014
13JAN2014   0    3   2014
.........................
15JUN2014   4   24   2014
20JUL2014   2   29   2014 
.........................
Last week of 2014
First week of 2015
........................
11JAN2015   1    2   2015
18JAN2015   2    3   2015
.........................
Last week of 2015
;run;&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;
&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, 02 Jul 2024 09:23:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-missing-dates-and-set-week-number/m-p/934374#M41996</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-07-02T09:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing dates and set week number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-missing-dates-and-set-week-number/m-p/934381#M41997</link>
      <description>&lt;P&gt;Hi There,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you say "&lt;SPAN&gt;Moreover, I would like to fill all the remaining weeks (that here are not shown because no events are present) back and forth with respect to each date." does this mean you want to create a dataset with all weeks ranging from 2014 up to 2015 with one record per week for each month?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2024 10:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-missing-dates-and-set-week-number/m-p/934381#M41997</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-07-02T10:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing dates and set week number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-missing-dates-and-set-week-number/m-p/934382#M41998</link>
      <description>&lt;P&gt;The problem with week numbers is that every year has 52 and a fraction weeks. That fractional week is partly in the previous year and partly in the current year. You can choose to deal with this any way you'd like, but I choose to deal with the Sundays rather than the week numbers. Also, is week 38 in August? People can't easily translate week number in their minds to calendar information. Make you life simpler and don't deal with week numbers, use the date of the Sunday start of the week.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is code so you can get all your Sundays into one data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all_sundays;
    do admission = '30DEC2013'd to '01JAN2016'd by 7;
        output;
    end;
    format admission date9.;
run;

data want;
    merge db all_sundays;
    by admission;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jul 2024 10:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-missing-dates-and-set-week-number/m-p/934382#M41998</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-07-02T10:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing dates and set week number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-missing-dates-and-set-week-number/m-p/934383#M41999</link>
      <description>Yes, exactly!</description>
      <pubDate>Tue, 02 Jul 2024 10:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-missing-dates-and-set-week-number/m-p/934383#M41999</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-07-02T10:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing dates and set week number</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-missing-dates-and-set-week-number/m-p/934385#M42000</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all_sundays;
	format date date9.;
	dcl hash _h_();
			 _h_.definekey('date');
			 _h_.definedone();
    do year = 2013 to 2016;
		do month=1 to 12;
			do week=1 to 5;
				date=nwkdom(week, 1, month, year);
				week_of_month=intck('week', intnx('month',date, 0), date) +1; 
				if _h_.check() then do;
					output;
					_h_.add();
				end;
				else continue;
			end;
		end;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In that case, can you give this a try?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2024 10:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-missing-dates-and-set-week-number/m-p/934385#M42000</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-07-02T10:47:08Z</dc:date>
    </item>
  </channel>
</rss>

