<?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: Find Tuesdays in a year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-Tuesdays-in-a-year/m-p/936489#M368097</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464920"&gt;@POOJAA&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464920"&gt;@POOJAA&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I do know approach 1 is giving correct ans. But can anyone plz explain the logic why approach&amp;nbsp; 2 is generating only 52 rows i.e and not 53 rows?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is because approach 2 counts &lt;EM&gt;Wednesdays&lt;/EM&gt; (weekday &lt;STRONG&gt;4&lt;/STRONG&gt;), not Tuesdays.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464920"&gt;@POOJAA&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Approach : 1 --&amp;gt; total tuesday are 53&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;if weekday(date) = &lt;STRONG&gt;3&lt;/STRONG&gt; then tuesday_count + 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Approach : 2 --&amp;gt; total tuesday can be 52 as 52 rows are generated&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;Day=weekday(i);
...
where day=&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;4&lt;/STRONG&gt;&lt;/FONT&gt;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is another mistake in your code with no impact on the count, though:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464920"&gt;@POOJAA&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Approach : 2 --&amp;gt; total tuesday can be 52 as 52 rows are generated&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;Day=weekday(i);
...
format day downame3.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p16z3pt9h9fdn6n1sxv7lzei34gp.htm" target="_blank" rel="noopener"&gt;DOWNAMEw. format&lt;/A&gt; expects &lt;EM&gt;SAS date values&lt;/EM&gt;, not weekday numbers 1 - 7. The latter would be interpreted as the date values &lt;FONT face="courier new,courier"&gt;'02JAN1960'd&lt;/FONT&gt;, ..., &lt;FONT face="courier new,courier"&gt;'08JAN1960'd&lt;/FONT&gt;, but those days were Saturday, ..., Friday, not Sunday, ..., Saturday, hence misleading labels. Apply the DOWNAME3. format to the date variable &lt;FONT face="courier new,courier"&gt;i&lt;/FONT&gt;, not variable &lt;FONT face="courier new,courier"&gt;day&lt;/FONT&gt;, to see the correct weekday names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 20 Jul 2024 14:35:48 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2024-07-20T14:35:48Z</dc:date>
    <item>
      <title>Find Tuesdays in a year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Tuesdays-in-a-year/m-p/936486#M368096</link>
      <description>&lt;P&gt;I'm trying to find&amp;nbsp;number of Tuesdays in a year using 2 approaches. I want to know why both give different answers!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Approach : 1 --&amp;gt; total tuesday are 53&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let year = 2024;
data count;
tuesday_count = 0;
do date = mdy(1, 1, &amp;amp;year) to mdy(12, 31, &amp;amp;year);
if weekday(date) = 3 then tuesday_count + 1;
end;
output;
keep tuesday_count;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Approach : 2 --&amp;gt; total tuesday can be 52 as 52 rows are generated&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data calendar (drop=yr1 yr2);
yr1="01jan2024"D;
yr2="31dec2024"D;
do i=yr1 to yr2;
Day=weekday(i);
output;
end;
format day downame3.;
run;

data new2;
set calendar;
format day downame3.;
where day=4;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I do know approach 1 is giving correct ans. But can anyone plz explain the logic why approach&amp;nbsp; 2 is generating only 52 rows i.e and not 53 rows?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jul 2024 13:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Tuesdays-in-a-year/m-p/936486#M368096</guid>
      <dc:creator>POOJAA</dc:creator>
      <dc:date>2024-07-20T13:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Find Tuesdays in a year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Tuesdays-in-a-year/m-p/936489#M368097</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464920"&gt;@POOJAA&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464920"&gt;@POOJAA&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I do know approach 1 is giving correct ans. But can anyone plz explain the logic why approach&amp;nbsp; 2 is generating only 52 rows i.e and not 53 rows?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is because approach 2 counts &lt;EM&gt;Wednesdays&lt;/EM&gt; (weekday &lt;STRONG&gt;4&lt;/STRONG&gt;), not Tuesdays.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464920"&gt;@POOJAA&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Approach : 1 --&amp;gt; total tuesday are 53&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;if weekday(date) = &lt;STRONG&gt;3&lt;/STRONG&gt; then tuesday_count + 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Approach : 2 --&amp;gt; total tuesday can be 52 as 52 rows are generated&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;Day=weekday(i);
...
where day=&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;4&lt;/STRONG&gt;&lt;/FONT&gt;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is another mistake in your code with no impact on the count, though:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464920"&gt;@POOJAA&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Approach : 2 --&amp;gt; total tuesday can be 52 as 52 rows are generated&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;Day=weekday(i);
...
format day downame3.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p16z3pt9h9fdn6n1sxv7lzei34gp.htm" target="_blank" rel="noopener"&gt;DOWNAMEw. format&lt;/A&gt; expects &lt;EM&gt;SAS date values&lt;/EM&gt;, not weekday numbers 1 - 7. The latter would be interpreted as the date values &lt;FONT face="courier new,courier"&gt;'02JAN1960'd&lt;/FONT&gt;, ..., &lt;FONT face="courier new,courier"&gt;'08JAN1960'd&lt;/FONT&gt;, but those days were Saturday, ..., Friday, not Sunday, ..., Saturday, hence misleading labels. Apply the DOWNAME3. format to the date variable &lt;FONT face="courier new,courier"&gt;i&lt;/FONT&gt;, not variable &lt;FONT face="courier new,courier"&gt;day&lt;/FONT&gt;, to see the correct weekday names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jul 2024 14:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Tuesdays-in-a-year/m-p/936489#M368097</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-07-20T14:35:48Z</dc:date>
    </item>
  </channel>
</rss>

