<?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 Data Logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-Logic/m-p/551257#M153153</link>
    <description>&lt;P&gt;&lt;BR /&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;i have the following , how will i be able to create wk variable and assign week to&lt;BR /&gt;each record without writing if conditions or proc format&amp;nbsp; i.e without having to change the code if any other days are added to the dataset&lt;BR /&gt;sub day &lt;BR /&gt;111 3 &lt;BR /&gt;111 12 &lt;BR /&gt;111 18&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;sub day wk&lt;BR /&gt;111 3 wk1&lt;BR /&gt;111 12 wk2&lt;BR /&gt;111 18 wk3&lt;/P&gt;
&lt;P&gt;Thanks &lt;BR /&gt;Al&lt;/P&gt;</description>
    <pubDate>Mon, 15 Apr 2019 21:16:54 GMT</pubDate>
    <dc:creator>Almoha</dc:creator>
    <dc:date>2019-04-15T21:16:54Z</dc:date>
    <item>
      <title>Data Logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Logic/m-p/551257#M153153</link>
      <description>&lt;P&gt;&lt;BR /&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;i have the following , how will i be able to create wk variable and assign week to&lt;BR /&gt;each record without writing if conditions or proc format&amp;nbsp; i.e without having to change the code if any other days are added to the dataset&lt;BR /&gt;sub day &lt;BR /&gt;111 3 &lt;BR /&gt;111 12 &lt;BR /&gt;111 18&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;sub day wk&lt;BR /&gt;111 3 wk1&lt;BR /&gt;111 12 wk2&lt;BR /&gt;111 18 wk3&lt;/P&gt;
&lt;P&gt;Thanks &lt;BR /&gt;Al&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 21:16:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Logic/m-p/551257#M153153</guid>
      <dc:creator>Almoha</dc:creator>
      <dc:date>2019-04-15T21:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Data Logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Logic/m-p/551260#M153155</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input sub day ;
cards;
111 3 
111 12 
111 18
;

data want;
set have;
wk=cats('wk',ceil(day/7));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 21:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Logic/m-p/551260#M153155</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-15T21:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: Data Logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Logic/m-p/551262#M153156</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input sub day ;
cards;
111 3 
111 12 
111 18
;

data want;
   set have;
   wk=cats('wk',week(day));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 21:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Logic/m-p/551262#M153156</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-04-15T21:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Data Logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Logic/m-p/551278#M153158</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/38344"&gt;@Almoha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;i have the following , how will i be able to create wk variable and assign week to&lt;BR /&gt;each record without writing if conditions or proc format&amp;nbsp; i.e without having to change the code if any other days are added to the dataset&lt;BR /&gt;sub day &lt;BR /&gt;111 3 &lt;BR /&gt;111 12 &lt;BR /&gt;111 18&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;sub day wk&lt;BR /&gt;111 3 wk1&lt;BR /&gt;111 12 wk2&lt;BR /&gt;111 18 wk3&lt;/P&gt;
&lt;P&gt;Thanks &lt;BR /&gt;Al&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You may need to define what you mean by "week". There are several common definitions that revolve around what day of the week starts the week and when to consider the start of the week at a year boundary. Given an actual SAS date value the WEEK function with a descriptor of 'U', 'V' or 'W' considers different rules.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;H4 class="xis-argument"&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;U&lt;/SPAN&gt;&lt;/H4&gt;
&lt;DIV class="xis-argumentDescription"&gt;
&lt;P class="xis-paraSimpleFirst"&gt;specifies the number-of-the-week within the year. Sunday is considered the first day of the week. The number-of-the-week value is represented as a decimal number in the range 0–53. Week 53 has no special meaning. The value of &lt;SPAN class="xis-nobr"&gt;&lt;CODE class="xis-codeDefaultStyle"&gt;week('31dec2006'd, 'u')&lt;/CODE&gt;&lt;/SPAN&gt; is 53. U is the default value.&lt;/P&gt;
&lt;TABLE class="xis-summary"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="xis-summaryTip"&gt;Tip&lt;/TD&gt;
&lt;TD class="xis-summaryText"&gt;The U and W descriptors are similar, except that the U descriptor considers Sunday as the first day of the week, and the W descriptor considers Monday as the first day of the week.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="xis-summarySee"&gt;See&lt;/TD&gt;
&lt;TD class="xis-summaryText"&gt;&lt;SPAN class="xis-xrefSee"&gt;&lt;A title="" href="http://127.0.0.1:58244/help/lefunctionsref.hlp/n1ka2ulrvrjlasn0z7beco2yrgas.htm#n1wfs8cpj0i7man1nx1f53cgg959" target="_blank"&gt;The U Descriptor&lt;/A&gt;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;DIV class="xis-argDescriptionPair" id="p0viazv0f795kon1a8axmxdi2kt7"&gt;
&lt;H4 class="xis-argument"&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;V&lt;/SPAN&gt;&lt;/H4&gt;
&lt;DIV class="xis-argumentDescription"&gt;
&lt;P class="xis-paraSimpleFirst"&gt;specifies the number-of-the-week whose value is represented as a decimal number in the range 1–53. Monday is considered the first day of the week and week 1 of the year is the week that includes both January 4 and the first Thursday of the year. If the first Monday of January is the 2nd, 3rd, or 4th, the preceding days are part of the last week of the preceding year.&lt;/P&gt;
&lt;TABLE class="xis-summary"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="xis-summarySee"&gt;See&lt;/TD&gt;
&lt;TD class="xis-summaryText"&gt;&lt;SPAN class="xis-xrefSee"&gt;&lt;A title="" href="http://127.0.0.1:58244/help/lefunctionsref.hlp/n1ka2ulrvrjlasn0z7beco2yrgas.htm#n0cnscgwulvcr7n1weeyrttzedob" target="_blank"&gt;The V Descriptor&lt;/A&gt;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="xis-argDescriptionPair" id="n12lunso19p7hjn1urc1lcz8y342"&gt;
&lt;H4 class="xis-argument"&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;W&lt;/SPAN&gt;&lt;/H4&gt;
&lt;DIV class="xis-argumentDescription"&gt;
&lt;P class="xis-paraSimpleFirst"&gt;specifies the number-of-the-week within the year. Monday is considered the first day of the week. The number-of-the-week value is represented as a decimal number in the range 0–53. Week 53 has no special meaning. The value of &lt;SPAN class="xis-nobr"&gt;&lt;CODE class="xis-codeDefaultStyle"&gt;week('31dec2006'd, 'w')&lt;/CODE&gt;&lt;/SPAN&gt; is 52.&lt;/P&gt;
&lt;TABLE class="xis-summary"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="xis-summaryTip"&gt;Tip&lt;/TD&gt;
&lt;TD class="xis-summaryText"&gt;The U and W descriptors are similar except that the U descriptor considers Sunday as the first day of the week, and the W descriptor considers Monday as the first day of the week.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="xis-summarySee"&gt;See&lt;/TD&gt;
&lt;TD class="xis-summaryText"&gt;&lt;SPAN class="xis-xrefSee"&gt;&lt;A title="" href="http://127.0.0.1:58244/help/lefunctionsref.hlp/n1ka2ulrvrjlasn0z7beco2yrgas.htm#p09qz5d0i3lxten1qzlhqi29hhxh" target="_blank"&gt;The W Descriptor&lt;/A&gt;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;TABLE class="xis-summary"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="xis-summaryDefault"&gt;Default&lt;/TD&gt;
&lt;TD class="xis-summaryText"&gt;U&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since SAS date values are numeric 3 could be considered as 3JAN1960 and for your example values the week number returned is as you request.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 23:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Logic/m-p/551278#M153158</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-15T23:01:29Z</dc:date>
    </item>
  </channel>
</rss>

